/
import.js
93 lines (86 loc) · 2.9 KB
/
import.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
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
var tap = require('tap');
var spawn = require('child_process').spawn;
var concat = require('concat-stream');
var hasDynamicImport = require('has-dynamic-import');
tap.test('importing mjs files', function (t) {
hasDynamicImport().then(function (hasSupport) {
if (hasSupport) {
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# mjs-a',
'ok 1 test ran',
'# mjs-b',
'ok 2 test ran after mjs-a',
'# mjs-c',
'ok 3 test ran after mjs-b',
'# mjs-d',
'ok 4 test ran after mjs-c',
'# mjs-e',
'ok 5 test ran after mjs-d',
'# mjs-f',
'ok 6 test ran after mjs-e',
'# mjs-g',
'ok 7 test ran after mjs-f',
'# mjs-h',
'ok 8 test ran after mjs-g',
'',
'1..8',
'# tests 8',
'# pass 8',
'',
'# ok'
].join('\n') + '\n\n');
};
var ps = tape('import/*.mjs');
ps.stdout.pipe(concat(tc));
ps.stderr.pipe(process.stderr);
ps.on('exit', function (code) {
t.equal(code, 0);
t.end();
});
} else {
t.pass('does not support dynamic import');
t.end();
}
});
});
tap.test('importing type: "module" files', function (t) {
hasDynamicImport().then(function (hasSupport) {
if (hasSupport) {
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# package-type-a',
'ok 1 test ran',
'# package-type-b',
'ok 2 test ran after package-type-a',
'# package-type-c',
'ok 3 test ran after package-type-b',
'',
'1..3',
'# tests 3',
'# pass 3',
'',
'# ok'
].join('\n') + '\n\n');
};
var ps = tape('import/package_type/*.js');
ps.stdout.pipe(concat(tc));
ps.stderr.pipe(process.stderr);
ps.on('exit', function (code) {
t.equal(code, 0);
t.end();
});
} else {
t.pass('does not support dynamic import');
t.end();
}
});
});
function tape(args) {
var proc = require('child_process');
var bin = __dirname + '/../bin/tape';
return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname });
}