This repository was archived by the owner on Nov 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
87 lines (77 loc) · 2.54 KB
/
Copy pathtest.js
File metadata and controls
87 lines (77 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var copyBrowserTo = require('./');
var test = require('tap').test;
var path = require('path');
var rimraf = require('rimraf');
var rsvp = require('rsvp');
var fs = require('fs');
test('trivial', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/trivial'), 'tmp').then(function (d) {
t.ok(d);
return checkExists('tmp');
}).catch(t.error).finally(cleanup).finally(t.end);
});
test('subdir', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/subdir'), 'tmp').then(function (d) {
t.ok(d);
return rsvp.Promise.all([
checkExists('tmp'),
checkExists('tmp/component1/sub/deepfile.js'),
checkNotExists('tmp/component1/excluded/deepfile2.js')
]);
}).catch(t.error).finally(cleanup).finally(t.end);
});
test('nested', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/nested'), 'tmp').then(function (d) {
t.ok(d);
return checkExists('tmp');
}).catch(t.error).finally(cleanup).finally(t.end);
});
test('irrelevant modules excluded', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/irrelevant'), 'tmp').then(function (d) {
t.ok(d);
return checkNotExists('tmp/irrelevant1');
}).catch(t.error).finally(cleanup).finally(t.end);
});
test('overrides work', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/override'), 'tmp').then(function (d) {
t.ok(d);
return checkExists('tmp/component1');
}).catch(t.error).finally(cleanup).finally(t.end);
});
test('overlap', function (t) {
copyBrowserTo(path.resolve(__dirname, 'test-fixtures/overlap'), 'tmp').then(t.fail).catch(function (e) {
t.ok(e);
t.equal(e.message, 'Overlapping packages found: component1');
}).finally(cleanup).finally(t.end);
});
function cleanup() {
return new rsvp.Promise(function (a) {
rimraf('tmp', a);
});
}
function checkNotExists(file) {
return new rsvp.Promise(function (a, r) {
fs.stat(file, function (err) {
if (err) {
if (err.code === 'ENOENT') {
a();
} else {
r(err);
}
} else {
r(new Error("File exists: " + file));
}
});
});
}
function checkExists(file) {
return new rsvp.Promise(function (a, r) {
fs.stat(file, function (err) {
if (err) {
r(err);
} else {
a();
}
});
});
}