Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Commit 5d79faa

Browse files
author
Eric Nijman
committedAug 31, 2018
feat: Add tests for samples
1 parent f9f7c49 commit 5d79faa

File tree

14 files changed

+79
-9
lines changed

14 files changed

+79
-9
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ For now there are 3 commands you can use.
7171
[cyclejs-usage]: samples/cyclejs/
7272
[react-favicon-usage]: samples/react-and-favicon/
7373
[react-graphql-usage]: samples/react-and-graphql/
74-
[react-sass-usage]: samples/react-and-sass/
74+
[react-scss-usage]: samples/react-and-scss/
7575
[root-usage]: samples/
7676

7777
# Dotfile
@@ -135,7 +135,7 @@ module.exports = {
135135
* [Cyclejs][cyclejs-usage]
136136
* [React and favicon][react-favicon-usage]
137137
* [React and graphql][react-graphql-usage]
138-
* [React and sass][react-sass-usage]
138+
* [React and scss][react-scss-usage]
139139

140140
# Help us
141141
Support us by giving feedback, opening a pull request or just by starring the project!

‎getConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const resolve = () => ({
6565
}
6666
});
6767

68-
const entry = (ent = './src/index.js') => ent;
68+
const entry = (ent = './src/index.js', cwd = process.cwd()) => path.resolve(cwd, ent);
6969

7070
const optimization = op => op || optimizations();
7171

@@ -119,7 +119,7 @@ const getConfig = args => {
119119
};
120120

121121
const checkOption = checkFile(configFile);
122-
logIntro(config);
122+
config.env !== 'test' && logIntro(config);
123123

124124
const moduleRules = () => ({
125125
rules: applyLoaders(config.preset.loaders.map(x => x(config))),

‎package.json

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"git-cz": "^1.7.1",
7676
"jest-cli": "^23.4.2",
7777
"jest-config": "^23.4.2",
78+
"webpacker-cyclejs-sample": "file:./samples/cyclejs",
79+
"webpacker-react-and-favicon-sample": "file:./samples/react-and-favicon",
80+
"webpacker-react-and-graphql-sample": "file:./samples/react-and-graphql",
81+
"webpacker-react-and-scss-sample": "file:./samples/react-and-scss",
7882
"xyz": "^3.0.0"
7983
}
8084
}

‎samples/cyclejs/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
},
1111
"author": "Renan Borges <renan@wearereasonablepeople.com> (https://github.com/renanborgez)",
1212
"license": "ISC",
13-
"devDependencies": {
13+
"dependencies": {
1414
"@cycle/dom": "^20.4.0",
1515
"@cycle/run": "^4.4.0",
16-
"webpacker": "github:wearereasonablepeople/webpacker#master",
1716
"xstream": "^11.7.0"
1817
}
1918
}

‎samples/react-and-favicon/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"author": "Renan Borges <renan@wearereasonablepeople.com> (https://github.com/renanborgez)",
1212
"license": "ISC",
13-
"devDependencies": {
13+
"dependencies": {
1414
"react": "^16.4.1",
1515
"react-dom": "^16.4.1"
1616
}

‎samples/react-and-graphql/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"author": "Renan Borges <renan@wearereasonablepeople.com> (https://github.com/renanborgez)",
1212
"license": "ISC",
13-
"devDependencies": {
13+
"dependencies": {
1414
"react": "^16.4.1",
1515
"react-dom": "^16.4.1"
1616
}
File renamed without changes.

‎samples/react-and-sass/package.json ‎samples/react-and-scss/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"author": "Renan Borges <renan@wearereasonablepeople.com> (https://github.com/renanborgez)",
1212
"license": "ISC",
13-
"devDependencies": {
13+
"dependencies": {
1414
"react": "^16.4.1",
1515
"react-dom": "^16.4.1"
1616
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎tests/samples/samples.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const {runner} = require('./testRunner');
2+
3+
runner({
4+
dir: 'cyclejs',
5+
name: 'Cyclejs',
6+
});
7+
8+
runner({
9+
dir: 'react-and-favicon',
10+
name: 'React and favicon',
11+
});
12+
13+
runner({
14+
dir: 'react-and-graphql',
15+
name: 'React and GraphQL',
16+
});
17+
18+
runner({
19+
dir: 'react-and-scss',
20+
name: 'React and SCSS',
21+
});

‎tests/samples/testRunner.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const MemoryFS = require('memory-fs');
4+
const {getConfig} = require('../../getConfig');
5+
6+
const runner = ({dir, name, config}) => {
7+
const fs = new MemoryFS();
8+
9+
const sample = (p = '') => path.join(__dirname, `../../samples/${dir}`, p);
10+
11+
const build = (args, cb) => {
12+
const config = getConfig(args);
13+
const compiler = webpack({
14+
...config,
15+
entry: path.resolve(args.cwd, './src/index'),
16+
});
17+
18+
compiler.outputFileSystem = fs;
19+
20+
compiler.run((err, stats) => {
21+
if(err) {
22+
throw new Error(err);
23+
}
24+
if(stats.hasErrors()) {
25+
throw new Error(stats.toString('errors-only'));
26+
}
27+
cb();
28+
});
29+
};
30+
31+
describe(`${name} sample`, () => {
32+
it('should not crash when building for development', done => {
33+
build({
34+
env: 'test',
35+
mode: 'development',
36+
cwd: sample(),
37+
config: sample('.webpacker.js'),
38+
...config,
39+
}, done);
40+
});
41+
});
42+
};
43+
44+
module.exports = {
45+
runner,
46+
};

0 commit comments

Comments
 (0)
This repository has been archived.