1+ import fs from 'fs/promises' ;
12import { jest } from '@jest/globals' ;
23import { promisify } from 'util' ;
34import BuildConfigManager from './BuildConfigManager.js' ;
@@ -8,10 +9,11 @@ describe('BuildConfigManager integration tests', () => {
89 jest . restoreAllMocks ( ) ;
910 } ) ;
1011 describe ( 'constructor' , ( ) => {
11- it ( 'should return an instance with correct watchOptions taken from the config file' , ( ) => {
12+ it ( 'should return an instance with correct watchOptions taken from the config file' , async ( ) => {
1213 const buildConfig = new BuildConfigManager ( {
1314 workDir : `${ cwd } /test/_mocks/build-config/valid-config` ,
1415 } ) ;
16+ await buildConfig . initConfig ( ) ;
1517 expect ( buildConfig . watchOptions ) . toBeInstanceOf ( Object ) ;
1618 expect ( buildConfig . watchOptions . files ) . toBeInstanceOf ( Array ) ;
1719 expect ( buildConfig . watchOptions . ignored ) . toBeInstanceOf ( Array ) ;
@@ -22,6 +24,7 @@ describe('BuildConfigManager integration tests', () => {
2224 const buildConfig = new BuildConfigManager ( {
2325 workDir : `${ cwd } /test/_mocks/build-config/valid-config` ,
2426 } ) ;
27+ await buildConfig . initConfig ( ) ;
2528 buildConfig . initWorker ( ) ;
2629 expect ( buildConfig . production ) . toBeInstanceOf ( Function ) ;
2730 await promisify ( buildConfig . production . bind ( buildConfig ) ) ( ) ;
@@ -31,6 +34,7 @@ describe('BuildConfigManager integration tests', () => {
3134 const buildConfig = new BuildConfigManager ( {
3235 workDir : `${ cwd } /test/_mocks/build-config/legacy-config` ,
3336 } ) ;
37+ await buildConfig . initConfig ( ) ;
3438 buildConfig . initWorker ( ) ;
3539 expect ( buildConfig . production ) . toBeInstanceOf ( Function ) ;
3640 await promisify ( buildConfig . production . bind ( buildConfig ) ) ( ) ;
@@ -40,19 +44,38 @@ describe('BuildConfigManager integration tests', () => {
4044 const buildConfig = new BuildConfigManager ( {
4145 workDir : `${ cwd } /test/_mocks/build-config/noworker-config` ,
4246 } ) ;
47+ await buildConfig . initConfig ( ) ;
4348 const initedBuildConfig = buildConfig . initWorker ( ) ;
4449 expect ( buildConfig . production ) . toBeInstanceOf ( Function ) ;
4550 await expect (
4651 promisify ( initedBuildConfig . production . bind ( initedBuildConfig ) ) ( ) ,
4752 ) . rejects . toContain ( 'worker terminated' ) ;
4853 buildConfig . stopWorker ( ) ;
4954 } ) ;
55+ it ( 'should download config from cornerstone github' , async ( ) => {
56+ const workDir = `${ cwd } /test/_mocks/build-config/no-config` ;
57+ const buildConfig = new BuildConfigManager ( {
58+ workDir,
59+ } ) ;
60+ try {
61+ await fs . access ( workDir ) ;
62+ } catch ( e ) {
63+ await fs . mkdir ( workDir , { recursive : true } ) ;
64+ }
65+ await buildConfig . initConfig ( ) ;
66+ buildConfig . initWorker ( ) ;
67+ expect ( buildConfig . production ) . toBeInstanceOf ( Function ) ;
68+ await promisify ( buildConfig . production . bind ( buildConfig ) ) ( ) ;
69+ buildConfig . stopWorker ( ) ;
70+ await fs . rm ( `${ cwd } /test/_mocks/build-config/no-config/stencil.conf.cjs` ) ;
71+ } ) ;
5072 } ) ;
5173 describe ( 'development method' , ( ) => {
5274 it ( 'should reload the browser when a message "reload" is received from stencil.conf.js (valid-config)' , async ( ) => {
5375 const buildConfig = new BuildConfigManager ( {
5476 workDir : `${ cwd } /test/_mocks/build-config/valid-config` ,
5577 } ) ;
78+ await buildConfig . initConfig ( ) ;
5679 expect ( buildConfig . development ) . toBeInstanceOf ( Function ) ;
5780 await new Promise ( ( done ) => buildConfig . initWorker ( ) . development ( { reload : done } ) ) ;
5881 buildConfig . stopWorker ( ) ;
@@ -61,6 +84,7 @@ describe('BuildConfigManager integration tests', () => {
6184 const buildConfig = new BuildConfigManager ( {
6285 workDir : `${ cwd } /test/_mocks/build-config/legacy-config` ,
6386 } ) ;
87+ await buildConfig . initConfig ( ) ;
6488 expect ( buildConfig . development ) . toBeInstanceOf ( Function ) ;
6589 await new Promise ( ( done ) => buildConfig . initWorker ( ) . development ( { reload : done } ) ) ;
6690 buildConfig . stopWorker ( ) ;
0 commit comments