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