Files: efcf9fd06b02fa9bcd28681b4c777224e19702bb / test / test-50-require-resolve-2 / main.js
2486 bytesRaw
1 | |
2 | |
3 | 'use strict'; |
4 | |
5 | const fs = require('fs'); |
6 | const path = require('path'); |
7 | const assert = require('assert'); |
8 | const utils = require('../utils.js'); |
9 | |
10 | assert(!module.parent); |
11 | assert(__dirname === process.cwd()); |
12 | |
13 | const target = process.argv[2] || 'host'; |
14 | const input = './test-x-index.js'; |
15 | const output = './run-time/test-output.exe'; |
16 | const output3 = './run-time-3/dummy'; |
17 | |
18 | let left, right, right3; |
19 | utils.mkdirp.sync(path.dirname(output)); |
20 | utils.mkdirp.sync(path.dirname(output3)); |
21 | |
22 | left = utils.spawn.sync( |
23 | 'node', [ path.basename(input) ], |
24 | { cwd: path.dirname(input) } |
25 | ); |
26 | |
27 | fs.readdirSync('./').some(function (file) { |
28 | if (/^test-/.test(file)) { |
29 | const nf = path.join( |
30 | path.dirname(file), |
31 | path.basename(path.dirname(output)), |
32 | path.basename(file) |
33 | ); |
34 | fs.writeFileSync( |
35 | nf, |
36 | fs.readFileSync(file, 'utf8').replace( |
37 | 'compile-time', 'run-time' |
38 | ) |
39 | ); |
40 | const nf3 = path.join( |
41 | path.dirname(file), |
42 | path.basename(path.dirname(output3)), |
43 | path.basename(file) |
44 | ); |
45 | fs.writeFileSync( |
46 | nf3, |
47 | fs.readFileSync(file, 'utf8').replace( |
48 | 'compile-time', 'run-time-3' |
49 | ) |
50 | ); |
51 | } |
52 | }); |
53 | |
54 | utils.pkg.sync([ |
55 | '--target', target, |
56 | '--output', output, input |
57 | ]); |
58 | |
59 | right = utils.spawn.sync( |
60 | './' + path.basename(output), [], |
61 | { cwd: path.dirname(output) } |
62 | ); |
63 | |
64 | right3 = utils.spawn.sync( |
65 | './' + path.join('..', path.dirname(output), path.basename(output)), [], |
66 | { cwd: path.dirname(output3) } |
67 | ); |
68 | |
69 | right = [ |
70 | 'require-code-J', |
71 | 'require-content-K', |
72 | 'require-content-L' |
73 | ].reduce(function (x, y) { |
74 | const r = x.replace( |
75 | new RegExp(y + '-run-time', 'g'), |
76 | y + '-compile-time'); |
77 | // assert(r !== x); |
78 | return r; |
79 | }, right); |
80 | |
81 | right3 = [ |
82 | 'require-code-J' |
83 | ].reduce(function (x, y) { |
84 | const r = x.replace( |
85 | new RegExp(y + '-run-time', 'g'), |
86 | y + '-compile-time'); |
87 | // assert(r !== x); |
88 | return r; |
89 | }, right3); |
90 | |
91 | right3 = [ |
92 | 'require-content-K', |
93 | 'require-content-L' |
94 | ].reduce(function (x, y) { |
95 | const r = x.replace( |
96 | new RegExp(y + '-run-time-3', 'g'), |
97 | y + '-compile-time'); |
98 | // assert(r !== x); |
99 | return r; |
100 | }, right3); |
101 | |
102 | if (left.length === 0) { |
103 | left = 'left is empty'; |
104 | } |
105 | |
106 | if (right.length === 0) { |
107 | right = 'right is empty'; |
108 | } |
109 | |
110 | if (right3.length === 0) { |
111 | right3 = 'right3 is empty'; |
112 | } |
113 | |
114 | assert.equal(left, right); |
115 | assert.equal(left, right3); |
116 | utils.vacuum.sync(path.dirname(output)); |
117 | utils.vacuum.sync(path.dirname(output3)); |
118 |
Built with git-ssb-web