@@ -2,10 +2,47 @@ import { Plugin as RollupPlugin, AcornNode } from 'rollup';
2
2
import { expect } from 'chai' ;
3
3
import path from 'path' ;
4
4
5
- import { createTestServer , fetchText , expectIncludes } from './test-helpers' ;
5
+ import { createTestServer , fetchText , expectIncludes , timeout } from './test-helpers' ;
6
6
import { fromRollup } from '../../src/index' ;
7
7
8
8
describe ( '@web/dev-server-rollup' , ( ) => {
9
+ describe ( 'buildStart' , ( ) => {
10
+ it ( 'awaits buildStart when starting a server' , async ( ) => {
11
+ let resolveBuildStartCalled : undefined | ( ( value : void ) => void ) ;
12
+ const buildStartCalledPromise = new Promise ( resolve => ( resolveBuildStartCalled = resolve ) ) ;
13
+
14
+ let resolveBuildStart : undefined | ( ( value : void ) => void ) ;
15
+ const plugin : RollupPlugin = {
16
+ name : 'my-plugin' ,
17
+ buildStart ( ) {
18
+ if ( resolveBuildStartCalled ) {
19
+ resolveBuildStartCalled ( ) ;
20
+ }
21
+ return new Promise ( resolve => ( resolveBuildStart = resolve ) ) ;
22
+ } ,
23
+ } ;
24
+
25
+ const serverPromise = createTestServer ( {
26
+ plugins : [ fromRollup ( ( ) => plugin ) ( ) ] ,
27
+ } ) ;
28
+
29
+ await buildStartCalledPromise ;
30
+
31
+ try {
32
+ const res = await Promise . race ( [ serverPromise , timeout ( 0 , 'timeout' ) ] ) ;
33
+ expect ( res ) . to . equal ( 'timeout' ) ;
34
+ if ( resolveBuildStart ) {
35
+ resolveBuildStart ( ) ;
36
+ }
37
+ const res2 = await Promise . race ( [ serverPromise , timeout ( 0 , 'timeout' ) ] ) ;
38
+ expect ( res2 ) . not . to . equal ( 'timeout' ) ;
39
+ } finally {
40
+ const { server } = await serverPromise ;
41
+ server . stop ( ) ;
42
+ }
43
+ } ) ;
44
+ } ) ;
45
+
9
46
describe ( 'resolveId' , ( ) => {
10
47
it ( 'can resolve imports, returning a string' , async ( ) => {
11
48
const plugin : RollupPlugin = {
0 commit comments