-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: James George <jamesgeorge998001@gmail.com>
- Loading branch information
1 parent
616187b
commit f61e7e0
Showing
4 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const { join, resolve } = require('path'); | ||
const rimraf = require('rimraf'); | ||
const { runPromptWithAnswers } = require('../../utils/test-utils'); | ||
const firstPrompt = 'Will your application have multiple bundles?'; | ||
|
||
const ENTER = '\x0D'; | ||
const genPath = join(__dirname, 'test-assets'); | ||
|
||
jest.setTimeout(100000); | ||
|
||
describe('init force flag', () => { | ||
beforeAll(() => { | ||
rimraf.sync(genPath); | ||
fs.mkdirSync(genPath); | ||
}); | ||
|
||
afterAll(() => { | ||
rimraf.sync(genPath); | ||
}); | ||
|
||
it('should scaffold webpack config', async () => { | ||
const { stdout } = await runPromptWithAnswers(genPath, ['init', '--force'], [`N${ENTER}`, ENTER, ENTER, ENTER, ENTER, ENTER]); | ||
|
||
expect(stdout).toBeTruthy(); | ||
expect(stdout).toContain(firstPrompt); | ||
|
||
// Skip test in case installation fails | ||
if (!fs.existsSync(resolve(genPath, './yarn.lock'))) { | ||
return; | ||
} | ||
|
||
// Test regressively files are scaffolded | ||
const files = ['./sw.js', './package.json', './src/index.js', './webpack.config.js']; | ||
|
||
// eslint-disable-next-line prettier/prettier | ||
files.forEach((file) => { | ||
expect(fs.existsSync(resolve(genPath, file))).toBeTruthy(); | ||
}); | ||
|
||
// Check package json is correctly configured | ||
const pkgJsonTests = () => { | ||
const pkgJson = require(join(genPath, './package.json')); | ||
expect(pkgJson).toBeTruthy(); | ||
expect(pkgJson['devDependencies']).toBeTruthy(); | ||
expect(pkgJson['devDependencies']['webpack']).toBeTruthy(); | ||
expect(pkgJson['scripts']['build'] == 'webpack').toBeTruthy(); | ||
}; | ||
expect(pkgJsonTests).not.toThrow(); | ||
}); | ||
}); |