|
1 | 1 | // @flow
|
2 | 2 |
|
3 | 3 | import assert from 'assert';
|
| 4 | +import {execSync} from 'child_process'; |
4 | 5 | import path from 'path';
|
5 | 6 |
|
6 | 7 | import {INTERNAL_ORIGINAL_CONSOLE} from '@parcel/logger';
|
7 |
| -import {bundle, fsFixture, overlayFS} from '@parcel/test-utils'; |
| 8 | +import {bundle} from '@parcel/test-utils'; |
8 | 9 | import sinon from 'sinon';
|
9 | 10 |
|
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 | + }); |
25 | 34 |
|
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 | + }); |
28 | 40 | });
|
29 | 41 |
|
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; |
41 | 45 |
|
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 | + }); |
73 | 50 |
|
74 |
| - await bundle(path.join(cwd, 'index.js'), { |
75 |
| - inputFS: overlayFS, |
| 51 | + afterEach(() => { |
| 52 | + process.exitCode = processExitCode; |
| 53 | + sinon.restore(); |
76 | 54 | });
|
77 | 55 |
|
78 |
| - assert(!process.exitCode); |
79 |
| - }); |
| 56 | + it('exit successfully when no errors are emitted', async () => { |
| 57 | + await bundle(successfulEntry); |
80 | 58 |
|
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 | + }); |
87 | 61 |
|
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); |
97 | 64 |
|
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 | + ); |
100 | 71 | });
|
101 |
| - |
102 |
| - assert.equal(process.exitCode, 1); |
103 |
| - assert( |
104 |
| - consoleError.calledWithMatch({message: 'Failed to report buildSuccess'}), |
105 |
| - ); |
106 | 72 | });
|
107 | 73 | });
|
0 commit comments