UNPKG

3.31 kBJavaScriptView Raw
1'use strict';
2var test = require('tape');
3var copyfiles = require('../');
4var rimraf = require('rimraf');
5var fs = require('fs');
6var mkdirp = require('mkdirp');
7
8function after(t) {
9 rimraf('output', function (err) {
10 t.error(err, 'rm out');
11 rimraf('input', function (err) {
12 t.error(err, 'rm input');
13 t.end();
14 });
15 });
16}
17function before(t) {
18 mkdirp('input/other', function (err) {
19 t.error(err, 'rm input');
20 t.end();
21 });
22}
23
24test('normal', function (t) {
25 t.test('setup', before);
26 t.test('copy stuff', function (t) {
27 fs.writeFileSync('input/a.txt', 'a');
28 fs.writeFileSync('input/b.txt', 'b');
29 fs.writeFileSync('input/c.js', 'c');
30 copyfiles(['input/*.txt', 'output'], function (err) {
31 t.error(err, 'copyfiles');
32 fs.readdir('output/input', function (err, files) {
33 t.error(err, 'readdir');
34 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');
35 t.end();
36 });
37 });
38 });
39 t.test('teardown', after);
40});
41test('exclude', function (t) {
42 t.test('setup', before);
43 t.test('copy stuff', function (t) {
44 fs.writeFileSync('input/a.txt', 'a');
45 fs.writeFileSync('input/b.txt', 'b');
46 fs.writeFileSync('input/c.js.txt', 'c');
47 copyfiles( ['input/*.txt', 'output'], {
48 exclude: '**/*.js.txt'
49 }, function (err) {
50 t.error(err, 'copyfiles');
51 fs.readdir('output/input', function (err, files) {
52 t.error(err, 'readdir');
53 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');
54 t.end();
55 });
56 });
57 });
58 t.test('teardown', after);
59});
60test('with up', function (t) {
61 t.test('setup', before);
62 t.test('copy stuff', function (t) {
63 fs.writeFileSync('input/a.txt', 'a');
64 fs.writeFileSync('input/b.txt', 'b');
65 fs.writeFileSync('input/c.js', 'c');
66 copyfiles(['input/*.txt', 'output'], 1, function (err) {
67 t.error(err, 'copyfiles');
68 fs.readdir('output', function (err, files) {
69 t.error(err, 'readdir');
70 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');
71 t.end();
72 });
73 });
74 });
75 t.test('teardown', after);
76});
77
78test('with up 2', function (t) {
79 t.test('setup', before);
80 t.test('copy stuff', function (t) {
81 fs.writeFileSync('input/other/a.txt', 'a');
82 fs.writeFileSync('input/other/b.txt', 'b');
83 fs.writeFileSync('input/other/c.js', 'c');
84 copyfiles(['input/**/*.txt', 'output'], 2, function (err) {
85 t.error(err, 'copyfiles');
86 fs.readdir('output', function (err, files) {
87 t.error(err, 'readdir');
88 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');
89 t.end();
90 });
91 });
92 });
93 t.test('teardown', after);
94});
95test('flatten', function (t) {
96 t.test('setup', before);
97 t.test('copy stuff', function (t) {
98 fs.writeFileSync('input/other/a.txt', 'a');
99 fs.writeFileSync('input/b.txt', 'b');
100 fs.writeFileSync('input/other/c.js', 'c');
101 copyfiles(['input/**/*.txt', 'output'], true, function (err) {
102 t.error(err, 'copyfiles');
103 fs.readdir('output', function (err, files) {
104 t.error(err, 'readdir');
105 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');
106 t.end();
107 });
108 });
109 });
110 t.test('teardown', after);
111});