This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3507e2c
commit 94cdb69
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
console.log('Starting b'); | ||
console.log('Finishing b'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} | ||
} |