Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
test: add unit test for #775 (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Apr 7, 2021
1 parent 3507e2c commit 94cdb69
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/test-775/a.js
@@ -0,0 +1,14 @@
'use strict';

console.log('Starting a');

// note : worker_threads in only valid for nodejs >= 12.0
const MAJOR_VERSION = parseInt(process.version.match(/v([0-9]+)/)[1], 10);
if (MAJOR_VERSION < 12) {
return;
}

const { Worker } = require('worker_threads');
// eslint-disable-next-line no-new
new Worker('./b.js');
console.log('Finishing a');
4 changes: 4 additions & 0 deletions test/test-775/b.js
@@ -0,0 +1,4 @@
'use strict';

console.log('Starting b');
console.log('Finishing b');
63 changes: 63 additions & 0 deletions test/test-775/main.js
@@ -0,0 +1,63 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

// note : worker_threads in only valid for nodejs >=12.0
const MAJOR_VERSION = parseInt(process.version.match(/v([0-9]+)/)[1], 10);
if (MAJOR_VERSION < 12) {
console.log('Ignoring test ');
return;
}

/* eslint-disable no-unused-vars */
const input = 'package.json';
const target = 'host';
const ext = process.platform === 'win32' ? '.exe' : '';
const output = 'output' + ext;

const inspect = ['ignore', 'ignore', 'pipe'];

const logPkg1 = utils.pkg.sync(
['--target', target, '--debug', '--output', output, input],
{ expect: 0 }
);

const log1 = utils.spawn.sync(path.join(__dirname, output), [], {
cwd: __dirname,
expect: 0,
});

assert.strictEqual(
log1,
`Starting a
Finishing a
Starting b
Finishing b
`
);

const logPkg2 = utils.pkg.sync(
['--target', target, '--debug', '--output', output, 'a.js'],
{ expect: 0 }
);

const log2 = utils.spawn.sync(path.join(__dirname, output), [], {
cwd: __dirname,
expect: 0,
});
assert.strictEqual(
log2,
`Starting a
Finishing a
Starting b
Finishing b
`
);
utils.vacuum.sync(output);
16 changes: 16 additions & 0 deletions test/test-775/package.json
@@ -0,0 +1,16 @@
{
"name": "a",
"version": "0.1.0",
"description": "proof",
"bin": "a.js",
"license": "UNLICENSED",
"devDependencies": {
"pkg": "^4.4.0"
},
"pkg": {
"scripts": [
"a.js",
"b.js"
]
}
}

0 comments on commit 94cdb69

Please sign in to comment.