@@ -15,12 +15,14 @@ const sinon = require('sinon');
15
15
const run = require ( '../' ) ;
16
16
17
17
const cwd = join ( __dirname , 'fixtures/' ) ;
18
- const file = join ( cwd , 'output/bundle.js' ) ;
18
+ const outputDir = join ( cwd , 'output' ) ;
19
+ const file = join ( outputDir , 'bundle.js' ) ;
19
20
const input = join ( cwd , 'input.js' ) ;
20
21
21
22
process . chdir ( cwd ) ;
22
23
23
24
const outputOptions = { file, format : 'cjs' } ;
25
+ const outputDirOptions = { dir : outputDir , format : 'cjs' } ;
24
26
25
27
let mockChildProcess ;
26
28
test . before ( ( ) => {
@@ -62,8 +64,7 @@ test('checks entry point facade module', async (t) => {
62
64
preserveEntrySignatures : 'strict' ,
63
65
plugins : [ run ( ) ]
64
66
} ) ;
65
- const outputDir = join ( cwd , 'output' ) ;
66
- await bundle . write ( { dir : outputDir , format : 'cjs' } ) ;
67
+ await bundle . write ( outputDirOptions ) ;
67
68
t . true ( mockChildProcess . calledWithExactly ( join ( outputDir , 'index.js' ) , [ ] , { } ) ) ;
68
69
} ) ;
69
70
@@ -97,6 +98,40 @@ test('throws an error when bundle is not written to disk', async (t) => {
97
98
) ;
98
99
} ) ;
99
100
101
+ test ( 'throws an error when input option is invalid' , async ( t ) => {
102
+ const testInput = join ( cwd , 'change-detect-input.js' ) ;
103
+ const bundle = await rollup ( {
104
+ input : [ input , testInput ] ,
105
+ plugins : [ run ( { input : 'something that is not an input' } ) ]
106
+ } ) ;
107
+ await t . throwsAsync (
108
+ async ( ) => {
109
+ await bundle . write ( outputDirOptions ) ;
110
+ } ,
111
+ {
112
+ instanceOf : Error ,
113
+ message : '@rollup/plugin-run could not find output chunk'
114
+ }
115
+ ) ;
116
+ } ) ;
117
+
118
+ test ( 'throws an error when there are multiple entry points' , async ( t ) => {
119
+ const testInput = join ( cwd , 'change-detect-input.js' ) ;
120
+ await t . throwsAsync (
121
+ async ( ) => {
122
+ await rollup ( {
123
+ input : [ input , testInput ] ,
124
+ plugins : [ run ( ) ]
125
+ } ) ;
126
+ } ,
127
+ {
128
+ instanceOf : Error ,
129
+ message :
130
+ '@rollup/plugin-run must have a single entry point; consider setting the `input` option'
131
+ }
132
+ ) ;
133
+ } ) ;
134
+
100
135
test ( 'detects changes - forks a new child process and kills older process' , async ( t ) => {
101
136
// eslint-disable-next-line no-shadow
102
137
const testInput = join ( cwd , 'change-detect-input.js' ) ;
@@ -120,6 +155,16 @@ test('allow the allowRestart option', async (t) => {
120
155
t . true ( mockChildProcess . calledWithExactly ( outputOptions . file , [ ] , { } ) ) ;
121
156
} ) ;
122
157
158
+ test ( 'allow the input option' , async ( t ) => {
159
+ const testInput = join ( cwd , 'change-detect-input.js' ) ;
160
+ const bundle = await rollup ( {
161
+ input : [ input , testInput ] ,
162
+ plugins : [ run ( { input } ) ]
163
+ } ) ;
164
+ await bundle . write ( outputDirOptions ) ;
165
+ t . true ( mockChildProcess . calledWithExactly ( join ( outputDir , 'input.js' ) , [ ] , { input } ) ) ;
166
+ } ) ;
167
+
123
168
test . after ( async ( ) => {
124
169
await del ( [ 'output' ] ) ;
125
170
} ) ;
0 commit comments