This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.js
80 lines (67 loc) · 1.96 KB
/
test.js
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
/* eslint-env mocha */
'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const makeDir = require('make-dir');
const del = require('del');
const Vinyl = require('vinyl');
const vulcanize = require('.');
function copyTestFile(src, dest) {
fs.writeFileSync(dest, fs.readFileSync(src, 'utf8'));
}
describe('should vulcanize web components:', () => {
const targets = [
'',
path.join('/abc'),
path.join('/xyz'),
path.join('/xyz', 'abs')
];
before(() => {
del.sync('tmp');
makeDir.sync('tmp');
for (const target of targets) {
const dest = path.join('tmp/src', target);
makeDir.sync(dest);
copyTestFile('fixture/index.html', path.join(dest, 'index.html'));
copyTestFile('fixture/import.html', path.join(dest, 'import.html'));
}
});
it('single', cb => {
const stream = vulcanize();
stream.on('data', file => {
if (/\.html$/.test(file.path)) {
assert.equal(file.relative, 'index.html');
assert(/Imported/.test(file.contents.toString()));
return;
}
assert.equal(file.relative, 'index.js');
assert(/Polymer/.test(file.contents.toString()));
});
stream.on('end', cb);
stream.end(new Vinyl({
cwd: __dirname,
base: path.join(__dirname, 'tmp', 'src'),
path: path.join('tmp', 'src', 'index.html'),
contents: fs.readFileSync(path.join('tmp', 'src', 'index.html'))
}));
});
it('multiple', cb => {
const stream = vulcanize();
stream.on('data', file => {
const t = path.dirname(file.path).replace(path.join(file.cwd, 'tmp', 'src'), '');
assert.notStrictEqual(targets.indexOf(t), -1);
assert(/Imported/.test(file.contents.toString()));
});
stream.on('end', cb);
targets.forEach(el => {
stream.write(new Vinyl({
cwd: __dirname,
base: path.join(__dirname, 'tmp', 'src'),
path: path.join(__dirname, 'tmp', 'src', el, 'index.html'),
contents: fs.readFileSync(path.join(__dirname, 'tmp', 'src', 'index.html'))
}));
});
stream.end();
});
});