@@ -5,7 +5,7 @@ import {execSync} from 'child_process';
5
5
import path from 'path' ;
6
6
7
7
import { INTERNAL_ORIGINAL_CONSOLE } from '@parcel/logger' ;
8
- import { bundle } from '@parcel/test-utils' ;
8
+ import { bundler } from '@parcel/test-utils' ;
9
9
import sinon from 'sinon' ;
10
10
11
11
describe ( 'reporters' , ( ) => {
@@ -16,7 +16,14 @@ describe('reporters', () => {
16
16
'index.js' ,
17
17
) ;
18
18
19
- let failingEntry = path . join (
19
+ let loadReporterFailureEntry = path . join (
20
+ __dirname ,
21
+ 'integration' ,
22
+ 'reporters-load-failure' ,
23
+ 'index.js' ,
24
+ ) ;
25
+
26
+ let failingReporterEntry = path . join (
20
27
__dirname ,
21
28
'integration' ,
22
29
'reporters-failure' ,
@@ -32,42 +39,56 @@ describe('reporters', () => {
32
39
) ;
33
40
} ) ;
34
41
35
- it ( 'exit with an error code when an error is emitted ' , ( ) => {
42
+ it ( 'exit with an error code when a reporter fails to load ' , ( ) => {
36
43
assert . throws ( ( ) =>
37
- execSync ( `parcel build --no-cache ${ failingEntry } ` , { stdio : 'ignore' } ) ,
44
+ execSync ( `parcel build --no-cache ${ loadReporterFailureEntry } ` , {
45
+ stdio : 'ignore' ,
46
+ } ) ,
47
+ ) ;
48
+ } ) ;
49
+
50
+ it ( 'exit with an error code when a reporter emits an error' , ( ) => {
51
+ assert . throws ( ( ) =>
52
+ execSync ( `parcel build --no-cache ${ failingReporterEntry } ` , {
53
+ stdio : 'ignore' ,
54
+ } ) ,
38
55
) ;
39
56
} ) ;
40
57
} ) ;
41
58
42
59
describe ( 'running on the programmatic api' , ( ) => {
43
- let consoleError ;
44
- let processExitCode ;
60
+ it ( 'resolves when no errors are emitted' , async ( ) => {
61
+ let buildEvent = await bundler ( successfulEntry ) . run ( ) ;
45
62
46
- beforeEach ( ( ) => {
47
- processExitCode = process . exitCode ;
48
- consoleError = sinon . stub ( INTERNAL_ORIGINAL_CONSOLE , 'error' ) ;
63
+ assert . equal ( buildEvent . type , 'buildSuccess' ) ;
49
64
} ) ;
50
65
51
- afterEach ( ( ) => {
52
- process . exitCode = processExitCode ;
53
- sinon . restore ( ) ;
54
- } ) ;
55
-
56
- it ( 'exit successfully when no errors are emitted' , async ( ) => {
57
- await bundle ( successfulEntry ) ;
66
+ it ( 'rejects when a reporter fails to load' , async ( ) => {
67
+ try {
68
+ let buildEvent = await bundler ( loadReporterFailureEntry ) . run ( ) ;
58
69
59
- assert ( ! process . exitCode ) ;
70
+ throw new Error ( buildEvent ) ;
71
+ } catch ( err ) {
72
+ assert . equal ( err . name , 'Error' ) ;
73
+ assert . deepEqual (
74
+ err . diagnostics . map ( d => d . message ) ,
75
+ [ 'Cannot find Parcel plugin "./test-reporter"' ] ,
76
+ ) ;
77
+ }
60
78
} ) ;
61
79
62
- it ( 'exit with an error code when an error is emitted' , async ( ) => {
63
- await bundle ( failingEntry ) ;
80
+ it ( 'rejects when a reporter emits an error' , async ( ) => {
81
+ try {
82
+ let buildEvent = await bundler ( failingReporterEntry ) . run ( ) ;
64
83
65
- assert . equal ( process . exitCode , 1 ) ;
66
- assert (
67
- consoleError . calledWithMatch ( {
68
- message : 'Failed to report buildSuccess' ,
69
- } ) ,
70
- ) ;
84
+ throw new Error ( buildEvent ) ;
85
+ } catch ( err ) {
86
+ assert . equal ( err . name , 'BuildError' ) ;
87
+ assert . deepEqual (
88
+ err . diagnostics . map ( d => d . message ) ,
89
+ [ 'Failed to report buildSuccess' ] ,
90
+ ) ;
91
+ }
71
92
} ) ;
72
93
} ) ;
73
94
} ) ;
0 commit comments