Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix local package runs #17

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions packages/bson-bench/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@ import {
type RunBenchmarkMessage
} from './common';

function reportResultAndQuit(result: BenchmarkResult) {
if (process.send) process?.send({ type: 'returnResult', result });
function exit(code: number) {
process.disconnect();
process.exit(0);
process.exit(code);
}

function reportResultAndQuit(result: BenchmarkResult) {
if (process.send) {
process.send({ type: 'returnResult', result }, null, {}, () => exit(0));
return;
}
exit(0);
}

function reportErrorAndQuit(error: Error) {
if (process.send)
process.send({
type: 'returnError',
error
});
process.disconnect();
process.exit(1);
if (process.send) {
process.send(
{
type: 'returnError',
error
},
null,
{},
() => exit(0)
);
return;
}

exit(1);
}

function run(bson: BSONLib | ConstructibleBSON, config: BenchmarkSpecification) {
Expand Down
11 changes: 10 additions & 1 deletion packages/bson-bench/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
* Note that this function should not be run in the same Node process that imports the installed
* module
**/
async install(): Promise<void> {
async install(inheritOutput = false): Promise<void> {
console.error('installing');
let source: string;
switch (this.type) {
case 'npm':
Expand All @@ -90,12 +91,20 @@
break;
}

const result = cp.execSync(`npm --version`, { encoding: 'utf8'});

Check failure on line 94 in packages/bson-bench/src/common.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `·`
console.error({ result });

const npmInstallProcess = cp.exec(
`npm install ${this.computedModuleName}@${source} --no-save`,
{ encoding: 'utf8', cwd: __dirname }
);

inheritOutput && npmInstallProcess.stderr?.pipe(process.stderr);
inheritOutput && npmInstallProcess.stdout?.pipe(process.stdout);
inheritOutput && npmInstallProcess.on('error', (e) => console.error({e }));

Check failure on line 104 in packages/bson-bench/src/common.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `(e)·=>·console.error({` with `e·=>·console.error({·`
const exitCode: number = (await once(npmInstallProcess, 'exit'))[0];
inheritOutput && console.error({ exitCode });

if (exitCode !== 0) {
throw new Error(`unable to install module: ${this.computedModuleName}@${source}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bson-bench/test/unit/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Package } from '../../lib/common';
import { clearTestedDeps } from '../utils';

describe('common functionality', function () {
describe.only('common functionality', function () {

Check failure on line 7 in packages/bson-bench/test/unit/common.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'describe.only' is restricted from being used
const BSON_PATH = process.env.BSON_PATH;

context('Package', function () {
Expand Down Expand Up @@ -107,7 +107,7 @@
function () {
it('throws an error', async function () {
const bson6Git = new Package('bson#58c002d87bca9bbe7c7001cc6acae54e90a951bcf');
const maybeError = await bson6Git.install().catch(error => error);
const maybeError = await bson6Git.install(true).catch(error => error);
expect(maybeError).to.be.instanceOf(Error);
});
}
Expand Down
Loading