git ssb

0+

cel-desktop / ssb-pkg



Tree: ca90b5ca0579ebdcc0635288bce4978e3fb200f5

Files: ca90b5ca0579ebdcc0635288bce4978e3fb200f5 / test / test-50-require-resolve-2 / main.js

2486 bytesRaw
1#!/usr/bin/env node
2
3'use strict';
4
5const fs = require('fs');
6const path = require('path');
7const assert = require('assert');
8const utils = require('../utils.js');
9
10assert(!module.parent);
11assert(__dirname === process.cwd());
12
13const target = process.argv[2] || 'host';
14const input = './test-x-index.js';
15const output = './run-time/test-output.exe';
16const output3 = './run-time-3/dummy';
17
18let left, right, right3;
19utils.mkdirp.sync(path.dirname(output));
20utils.mkdirp.sync(path.dirname(output3));
21
22left = utils.spawn.sync(
23 'node', [ path.basename(input) ],
24 { cwd: path.dirname(input) }
25);
26
27fs.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
54utils.pkg.sync([
55 '--target', target,
56 '--output', output, input
57]);
58
59right = utils.spawn.sync(
60 './' + path.basename(output), [],
61 { cwd: path.dirname(output) }
62);
63
64right3 = utils.spawn.sync(
65 './' + path.join('..', path.dirname(output), path.basename(output)), [],
66 { cwd: path.dirname(output3) }
67);
68
69right = [
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
81right3 = [
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
91right3 = [
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
102if (left.length === 0) {
103 left = 'left is empty';
104}
105
106if (right.length === 0) {
107 right = 'right is empty';
108}
109
110if (right3.length === 0) {
111 right3 = 'right3 is empty';
112}
113
114assert.equal(left, right);
115assert.equal(left, right3);
116utils.vacuum.sync(path.dirname(output));
117utils.vacuum.sync(path.dirname(output3));
118

Built with git-ssb-web