Skip to content

Commit f94539b

Browse files
Add cli handling
1 parent 81b40a1 commit f94539b

File tree

12 files changed

+87
-87
lines changed

12 files changed

+87
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"reporters": ["./test-reporter"]
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { Reporter } = require('@parcel/plugin');
2+
3+
module.exports = new Reporter({
4+
async report({ event }) {
5+
if (event.type === 'buildSuccess') {
6+
throw new Error('Failed to report buildSuccess');
7+
}
8+
}
9+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "test-reporter",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}

packages/core/integration-tests/test/integration/reporters-failure/yarn.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"reporters": ["./test-reporter"]
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { Reporter } = require('@parcel/plugin');
2+
3+
module.exports = new Reporter({
4+
async report({ event }) {}
5+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "test-reporter",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}

packages/core/integration-tests/test/integration/reporters-success/yarn.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,73 @@
11
// @flow
22

33
import assert from 'assert';
4+
import {execSync} from 'child_process';
45
import path from 'path';
56

67
import {INTERNAL_ORIGINAL_CONSOLE} from '@parcel/logger';
7-
import {bundle, fsFixture, overlayFS} from '@parcel/test-utils';
8+
import {bundle} from '@parcel/test-utils';
89
import sinon from 'sinon';
910

10-
describe.only('reporters', () => {
11-
let consoleError;
12-
let processExitCode;
13-
let dir = path.join(__dirname, 'reporters');
14-
15-
beforeEach(async () => {
16-
processExitCode = process.exitCode;
17-
consoleError = sinon.stub(INTERNAL_ORIGINAL_CONSOLE, 'error');
18-
await overlayFS.mkdirp(dir);
19-
});
20-
21-
afterEach(async () => {
22-
process.exitCode = processExitCode;
23-
sinon.restore();
24-
});
11+
describe('reporters', () => {
12+
let successfulEntry = path.join(
13+
__dirname,
14+
'integration',
15+
'reporters-success',
16+
'index.js',
17+
);
18+
19+
let failingEntry = path.join(
20+
__dirname,
21+
'integration',
22+
'reporters-failure',
23+
'index.js',
24+
);
25+
26+
describe('running on the cli', () => {
27+
it('exit successfully when no errors are emitted', () => {
28+
assert.doesNotThrow(() =>
29+
execSync(`parcel build --no-cache ${successfulEntry}`, {
30+
stdio: 'ignore',
31+
}),
32+
);
33+
});
2534

26-
after(async () => {
27-
await overlayFS.rimraf(dir);
35+
it('exit with an error code when an error is emitted', () => {
36+
assert.throws(() =>
37+
execSync(`parcel build --no-cache ${failingEntry}`, {stdio: 'ignore'}),
38+
);
39+
});
2840
});
2941

30-
async function createReporterFixture(name: string, reporter: string) {
31-
let cwd = path.join(dir, name);
32-
33-
await overlayFS.mkdirp(cwd);
34-
35-
await fsFixture(overlayFS, cwd)`
36-
index.js:
37-
export function main() {}
38-
39-
test-reporter/index.js:
40-
${reporter}
42+
describe('running on the programmatic api', () => {
43+
let consoleError;
44+
let processExitCode;
4145

42-
test-reporter/package.json:
43-
{
44-
"name": "test-reporter",
45-
"main": "index.js",
46-
"version": "1.0.0"
47-
}
48-
49-
.parcelrc:
50-
{
51-
"extends": "@parcel/config-default",
52-
"reporters": ["./test-reporter"]
53-
}
54-
55-
yarn.lock: {}
56-
`;
57-
58-
return cwd;
59-
}
60-
61-
it('exit successfully when no errors are emitted', async () => {
62-
let cwd = await createReporterFixture(
63-
'success',
64-
`
65-
test-reporter/index.js:
66-
const { Reporter } = require('@parcel/plugin');
67-
68-
module.exports = new Reporter({
69-
async report({ event }) {}
70-
});
71-
`,
72-
);
46+
beforeEach(() => {
47+
processExitCode = process.exitCode;
48+
consoleError = sinon.stub(INTERNAL_ORIGINAL_CONSOLE, 'error');
49+
});
7350

74-
await bundle(path.join(cwd, 'index.js'), {
75-
inputFS: overlayFS,
51+
afterEach(() => {
52+
process.exitCode = processExitCode;
53+
sinon.restore();
7654
});
7755

78-
assert(!process.exitCode);
79-
});
56+
it('exit successfully when no errors are emitted', async () => {
57+
await bundle(successfulEntry);
8058

81-
it('exit with an error code when an error is emitted', async () => {
82-
let cwd = await createReporterFixture(
83-
'error',
84-
`
85-
test-reporter/index.js:
86-
const { Reporter } = require('@parcel/plugin');
59+
assert(!process.exitCode);
60+
});
8761

88-
module.exports = new Reporter({
89-
async report({ event }) {
90-
if (event.type === 'buildSuccess') {
91-
throw new Error('Failed to report buildSuccess');
92-
}
93-
}
94-
});
95-
`,
96-
);
62+
it('exit with an error code when an error is emitted', async () => {
63+
await bundle(failingEntry);
9764

98-
await bundle(path.join(cwd, 'index.js'), {
99-
inputFS: overlayFS,
65+
assert.equal(process.exitCode, 1);
66+
assert(
67+
consoleError.calledWithMatch({
68+
message: 'Failed to report buildSuccess',
69+
}),
70+
);
10071
});
101-
102-
assert.equal(process.exitCode, 1);
103-
assert(
104-
consoleError.calledWithMatch({message: 'Failed to report buildSuccess'}),
105-
);
10672
});
10773
});

packages/core/parcel/src/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ async function run(
404404
await exit(1);
405405
}
406406

407-
await exit();
407+
await exit(process.exitCode);
408408
}
409409
}
410410

0 commit comments

Comments
 (0)