git ssb

0+

cel-desktop / ssb-pkg



Tree: 65191f9a9664f013ebe726bb95a1a54b086e1bd5

Files: 65191f9a9664f013ebe726bb95a1a54b086e1bd5 / test / test-50-spawn / main.js

1839 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 host = 'node' + process.version.match(/^v(\d+)/)[1];
14const target = process.argv[2] || host;
15
16function rnd () {
17 return Math.random().toString().slice(-6);
18}
19
20const pairs = fs.readdirSync('.').filter(function (f) {
21 return (/\.js$/.test(f)) &&
22 (f !== 'main.js') &&
23 (!(/-child\.js$/.test(f)));
24}).map(function (f) {
25 return ({
26 input: f, output: './test-output-' + rnd() + '.exe'
27 });
28});
29
30assert(pairs.length > 6);
31
32function stripTraceOpt (lines) {
33 return lines.split('\n').filter(function (line) {
34 return (line.indexOf('[disabled optimization') < 0) &&
35 (line.indexOf('[marking') < 0) &&
36 (line.indexOf('[compiling method') < 0) &&
37 (line.indexOf('[optimizing') < 0) &&
38 (line.indexOf('[completed optimizing') < 0) &&
39 (line.indexOf('einfo:') < 0);
40 }).join('\n');
41}
42
43pairs.some(function (pair) {
44 const input = pair.input;
45 const output = pair.output;
46
47 let left, right;
48 utils.mkdirp.sync(path.dirname(output));
49
50 left = utils.spawn.sync(
51 'node', [ path.basename(input) ],
52 { cwd: path.dirname(input) }
53 );
54
55 utils.pkg.sync([
56 '--target', target,
57 '--output', output, input
58 ]);
59
60 right = utils.spawn.sync(
61 './' + path.basename(output), [],
62 { cwd: path.dirname(output) }
63 );
64
65 right = stripTraceOpt(right);
66 left = stripTraceOpt(left);
67 if (left !== right) {
68 console.log(JSON.stringify(pair));
69 console.log('<<left<<\n' + left);
70 console.log('>>right>>\n' + right);
71 throw new Error('Assertion');
72 }
73
74 utils.vacuum.sync(output);
75 console.log(__dirname, input, 'ok');
76});
77

Built with git-ssb-web