/
init-language-css.test.js
83 lines (69 loc) · 2.78 KB
/
init-language-css.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'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 DOWN = '\x1B\x5B\x42';
const genPath = join(__dirname, 'test-assets');
describe('init with SCSS', () => {
beforeAll(() => {
rimraf.sync(genPath);
fs.mkdirSync(genPath);
});
it('should use SCSS', async () => {
const { stdout } = await runPromptWithAnswers(
genPath,
['init'],
[`N${ENTER}`, ENTER, ENTER, ENTER, `${DOWN}${DOWN}${ENTER}`, `Y${ENTER}`, `apple${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 = ['./package.json', './.yo-rc.json', './src/index.js', './webpack.config.js'];
files.forEach((file) => {
expect(fs.existsSync(resolve(genPath, file))).toBeTruthy();
});
const webpackConfig = require(join(genPath, './webpack.config.js'));
expect(webpackConfig.module.rules).toEqual([
{
test: /.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader, // eslint-disable-line
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
]);
// Check if 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['devDependencies']['webpack-dev-server']).toBeTruthy();
expect(pkgJson['devDependencies']['node-sass']).toBeTruthy();
expect(pkgJson['devDependencies']['mini-css-extract-plugin']).toBeTruthy();
expect(pkgJson['scripts']['build'] == 'webpack').toBeTruthy();
expect(pkgJson['scripts']['serve'] == 'webpack serve').toBeTruthy();
};
expect(pkgJsonTests).not.toThrow();
});
});