Files: 938b7ea4cfaa3cef6e1690b9ef3ea8bd7a0d2de1 / test / test-50-fs-runtime-layer-2 / main.js
1730 bytesRaw
1 | |
2 | |
3 | /* eslint-disable no-multi-spaces */ |
4 | |
5 | 'use strict'; |
6 | |
7 | const path = require('path'); |
8 | const assert = require('assert'); |
9 | const utils = require('../utils.js'); |
10 | |
11 | assert(!module.parent); |
12 | assert(__dirname === process.cwd()); |
13 | |
14 | const host = 'node' + process.version.match(/^v(\d+)/)[1]; |
15 | const target = process.argv[2] || host; |
16 | const input = './test-x-index.js'; |
17 | const output = './run-time/test-output.exe'; |
18 | |
19 | // see readFromSnapshot "NODE_VERSION_MAJOR" |
20 | |
21 | function bitty (version) { |
22 | return (2 * (/^(node|v)?4/.test(version))) | |
23 | (2 * (/^(node|v)?5/.test(version))) | |
24 | (4 * (/^(node|v)?6/.test(version))) | |
25 | (4 * (/^(node|v)?7/.test(version))) | |
26 | (4 * (/^(node|v)?8/.test(version))) | |
27 | (4 * (/^(node|v)?9/.test(version))) | |
28 | (8 * (/^(node|v)?10/.test(version))) | |
29 | (8 * (/^(node|v)?11/.test(version))) | |
30 | (16 * (/^(node|v)?12/.test(version))) | |
31 | (16 * (/^(node|v)?13/.test(version))) | |
32 | (16 * (/^(node|v)?14/.test(version))); |
33 | } |
34 | |
35 | const version1 = process.version; |
36 | const version2 = target; |
37 | if (bitty(version1) !== bitty(version2)) return; |
38 | |
39 | let left, right; |
40 | utils.mkdirp.sync(path.dirname(output)); |
41 | |
42 | left = utils.spawn.sync( |
43 | 'node', [ path.basename(input) ], |
44 | { cwd: path.dirname(input) } |
45 | ); |
46 | |
47 | utils.pkg.sync([ |
48 | '--target', target, |
49 | '--output', output, input |
50 | ]); |
51 | |
52 | right = utils.spawn.sync( |
53 | './' + path.basename(output), [], |
54 | { cwd: path.dirname(output) } |
55 | ); |
56 | |
57 | left = left.split('\n'); |
58 | right = right.split('\n'); |
59 | // right may have less lines, premature exit, |
60 | // less trusted, so using left.length here |
61 | for (let i = 0; i < left.length; i += 1) { |
62 | assert.equal(left[i], right[i]); |
63 | } |
64 | |
65 | utils.vacuum.sync(path.dirname(output)); |
66 |
Built with git-ssb-web