Skip to content

Commit d3595c4

Browse files
Technical/issue 56 organize tests (#74)
* WIP tests * all happy paths for config * WIP refactoring setup to use cwd context * WIP refactoring * more cases working * cleanup * formatting * new nested case * more cases * page template case * clean up tests * config workspace case * smoke testing and creating test bed * using more smoke testing * added testing for deeper 404 and index testing * remove eslint * watch mode * code coverage and reporting * reuse test bed * playing around with smoke tests * cleanup * delete fixtures * remove commented out code * increase test timeout * one minute? * build config error handling * relax smoke test content testing * fix spec using hash * better test and build output cleanup * Technical/issue 56 organize tests smoke test refactor (#75) * integrating smoke tests * full smoke test integration * cleanup * fix linting * improve error message * Fix test async and teardown (#77) * fix: removed smoke test promises, implemented shared context using this * fix: remove TODO
1 parent e791eaa commit d3595c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1251
-1213
lines changed

.github/CONTRIBUTING.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,35 @@ To develop for the project, you'll want to follow these steps:
2222
1. Run `yarn install`
2323

2424

25-
## Unit Testing
26-
Unit tests have been written that can be run using
25+
## Testing
26+
Greenwood follows [BDD style testing](https://en.wikipedia.org/wiki/Behavior-driven_development) through "cases". Cases are used to capture the capabilities and features of Greenwood when running its various commands in a way that is close to how the user would actually expect the tool to work and so generally revolves around testing the build output of running `greenwood build`.
27+
28+
### Guidelines
29+
Cases follow a convention starting with the command (e.g. `build`) and and the capability and features being tested, like configuration with a particular option (e.g. `publicPath`):
30+
```shell
31+
<command>.<capability>.<feature>.spec.js
32+
```
33+
34+
Examples:
35+
- _build.default.spec.js_ - Would test `greenwood build` with no config and no workspace.
36+
- _build.config.workspace-custom.spec.js_ - Would test `greenwood build` with a config that had a custom `workspace`
37+
- _build.config.workspace-public-path.spec.js_ - Would test `greenwood build` with a config that had a custom `workspace` and `publicPath` set.
38+
39+
### Running Tests
40+
To run tests in watch mode, use:
41+
```shell
42+
$ yarn test:tdd
43+
```
44+
45+
To verify compliance with coverage and watermark thresholds (what CI server runs), use:
2746
```shell
2847
$ yarn test
2948
```
3049

31-
Note, you can use the following to adjust how many mocha tests get run:
32-
- `describe.only` / `it.only`: only run this block
33-
- `xdescribe` / `xit`: dont run this block
50+
Below are some tips to help with running / debugging tests
51+
- `describe.only` / `it.only`: only runs this block
52+
- `xdescribe` / `xit`: dont run this block
53+
- uncomment `setup.teardownTestBed()` in a case to see the build output without it getting cleaned
54+
- use `new TestBed(true)` get debug output from Greenwood when running tests
55+
56+
> **PLEASE DO NOT COMMIT ANY OF THESE ABOVE CHANGES THOUGH**

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.log
22
.greenwood/
3+
.nyc_output/
4+
coverage/
35
node_modules/
46
public/

nyc.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
3+
all: true,
4+
5+
include: [
6+
'packages/cli/lib/**/*.js',
7+
'packages/cli/tasks/*.js'
8+
],
9+
10+
reporter: [
11+
'cobertura',
12+
'html',
13+
'text',
14+
'text-summary'
15+
],
16+
17+
checkCoverage: true,
18+
19+
statements: 85,
20+
branches: 65,
21+
functions: 90,
22+
lines: 85,
23+
24+
watermarks: {
25+
statements: [75, 85],
26+
branches: [75, 85],
27+
functions: [75, 85],
28+
lines: [75, 85]
29+
}
30+
};

package.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,42 @@
77
"author": "Owen Buckley <[email protected]>",
88
"license": "MIT",
99
"scripts": {
10-
"clean": "rimraf ./.greenwood && rimraf ./public",
10+
"clean": "rimraf ./**/.greenwood/** && rimraf ./**/public/** && rimraf ./coverage",
1111
"lint": "eslint \"./packages/**/**/*.js\" \"./test/**/**/*.js\"",
1212
"build": "node ./packages/cli/index.js build",
1313
"serve": "yarn clean && yarn build && cd ./public && ws",
1414
"develop": "yarn clean && node ./packages/cli/index.js develop",
15-
"test": "yarn clean && mocha --timeout 15000"
15+
"test": "yarn clean && nyc mocha ./test/**/**/**/*.spec.js --timeout 30000",
16+
"test:tdd": "yarn clean && mocha --watch ./test/**/**/**/*.spec.js --timeout 15000"
1617
},
1718
"dependencies": {
1819
"@babel/core": "^7.4.0",
1920
"@babel/preset-env": "^7.4.1",
2021
"babel-loader": "^8.0.5",
2122
"babel-plugin-transform-builtin-classes": "^0.6.1",
22-
"chai": "^4.2.0",
23-
"chai-as-promised": "^7.1.1",
2423
"chalk": "^2.4.2",
2524
"colors": "^1.3.3",
2625
"commander": "^2.20.0",
27-
"concurrently": "^4.1.0",
2826
"css-loader": "^2.1.1",
2927
"css-to-string-loader": "^0.1.3",
3028
"cssnano": "^4.1.10",
3129
"eslint": "^5.15.3",
32-
"eslint-loader": "^2.1.2",
3330
"file-loader": "^3.0.1",
3431
"filewatcher-webpack-plugin": "^1.2.0",
3532
"front-matter": "^3.0.1",
36-
"fs-extra": "^7.0.1",
3733
"glob": "^7.1.3",
3834
"glob-promise": "^3.4.0",
3935
"html-webpack-plugin": "^3.2.0",
4036
"jsdom": "^14.0.0",
4137
"lit-element": "^2.0.1",
4238
"lit-redux-router": "^0.8.5",
4339
"local-web-server": "^2.6.1",
44-
"mocha": "^6.0.2",
4540
"postcss-cssnext": "^3.1.0",
4641
"postcss-loader": "^3.0.0",
4742
"puppeteer": "^1.13.0",
4843
"pwa-helpers": "^0.9.1",
4944
"redux": "^4.0.1",
5045
"redux-thunk": "^2.3.0",
51-
"rimraf": "^2.6.3",
5246
"wc-markdown-loader": "^0.1.0",
5347
"webpack": "^4.29.6",
5448
"webpack-cli": "^3.3.0",
@@ -57,6 +51,10 @@
5751
"webpack-merge": "^4.2.1"
5852
},
5953
"devDependencies": {
60-
"http-server": "^0.11.1"
54+
"chai": "^4.2.0",
55+
"http-server": "^0.11.1",
56+
"mocha": "^6.1.4",
57+
"nyc": "^14.0.0",
58+
"rimraf": "^2.6.3"
6159
}
6260
}

packages/cli/config/.eslintrc

-201
This file was deleted.

packages/cli/config/webpack.config.common.js

-7
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ module.exports = (config, context) => {
4444

4545
module: {
4646
rules: [{
47-
test: /\.js$/,
48-
enforce: 'pre',
49-
loader: 'eslint-loader',
50-
options: {
51-
configFile: path.join(__dirname, './.eslintrc')
52-
}
53-
}, {
5447
test: /\.js$/,
5548
loader: 'babel-loader',
5649
options: {

packages/cli/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ if (program.parse.length === 0) {
3939
}
4040

4141
const run = async() => {
42-
process.env.NODE_ENV = MODE === 'develop' ? 'development' : 'production';
4342

4443
try {
4544
const compilation = await generateCompilation();

0 commit comments

Comments
 (0)