2020-04-12 14:34:16 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-06-12 15:23:38 -04:00
|
|
|
import { assert } from "../../testing/asserts.ts";
|
2020-04-12 14:34:16 -04:00
|
|
|
import { copyFile, copyFileSync } from "./_fs_copy.ts";
|
|
|
|
import { existsSync } from "./_fs_exists.ts";
|
|
|
|
|
|
|
|
const destFile = "./destination.txt";
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-04-12 14:34:16 -04:00
|
|
|
name: "[std/node/fs] copy file",
|
|
|
|
fn: async () => {
|
2020-05-25 09:35:11 -04:00
|
|
|
const sourceFile = Deno.makeTempFileSync();
|
2020-04-12 14:34:16 -04:00
|
|
|
const err = await new Promise((resolve) => {
|
2020-05-25 09:35:11 -04:00
|
|
|
copyFile(sourceFile, destFile, (err?: Error | null) => resolve(err));
|
2020-04-12 14:34:16 -04:00
|
|
|
});
|
|
|
|
assert(!err);
|
|
|
|
assert(existsSync(destFile));
|
2020-05-25 09:35:11 -04:00
|
|
|
Deno.removeSync(sourceFile);
|
2020-04-12 14:34:16 -04:00
|
|
|
Deno.removeSync(destFile);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-04-12 14:34:16 -04:00
|
|
|
name: "[std/node/fs] copy file sync",
|
|
|
|
fn: () => {
|
2020-05-25 09:35:11 -04:00
|
|
|
const sourceFile = Deno.makeTempFileSync();
|
|
|
|
copyFileSync(sourceFile, destFile);
|
2020-04-12 14:34:16 -04:00
|
|
|
assert(existsSync(destFile));
|
2020-05-25 09:35:11 -04:00
|
|
|
Deno.removeSync(sourceFile);
|
2020-04-12 14:34:16 -04:00
|
|
|
Deno.removeSync(destFile);
|
|
|
|
},
|
|
|
|
});
|