Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
Use Jest, round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed Oct 26, 2016
1 parent 1af9ab4 commit c13d849
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 280 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ before_install:
- npm prune

script:
- npm run test-with-coverage && npm run docs-webpack-2-test
- npm run test && npm run docs-webpack-2-test && docs-webpack-2-reset

after_success: npm run coverage
9 changes: 0 additions & 9 deletions __tests__/README.md

This file was deleted.

102 changes: 0 additions & 102 deletions __tests__/build-result.js

This file was deleted.

87 changes: 0 additions & 87 deletions __tests__/cli.js

This file was deleted.

7 changes: 0 additions & 7 deletions __tests__/jest-config.json

This file was deleted.

14 changes: 14 additions & 0 deletions e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# End to end tests

End-to-end testing is a methodology used to test whether the flow of an
application is performing as designed from start to finish.

Tests here need to be run with a transpiled sources & a test folder ready to run

```console
npm run transpile
npm run test-phenomic-theme-base:prepare
npm run e2e:tests
```

Otherwise you can just use `npm test` to run every tests.
35 changes: 35 additions & 0 deletions e2e-tests/__tests__/cli-arg-port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
exec,
execOpts,
phenomic,
timing,
maxTimeout,
} from "./utils"

it("should NOT throw if port is used",
() => new Promise((resolve, reject) => {
const app = require("express")()
const server = app.listen(3333, (err) => {
if (err) {
reject(err)
}

const child = exec(
`${ phenomic } start --open=false --devPort=3333`, execOpts,

(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)

// server need to be killed manually
const timeout = setTimeout(() => {
server.close()
child.kill()
resolve()
}, timing)
})
}), maxTimeout)
30 changes: 30 additions & 0 deletions e2e-tests/__tests__/cli-args-know.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
exec,
execOpts,
phenomic,
timing,
maxTimeout,
} from "./utils"

it("should NOT throw if a CLI flag is recognized",
() => new Promise((resolve, reject) => {
const child = exec(
`${ phenomic } start --open=false --devPort=4000`, execOpts,

// should die quickly...
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)

// ...or be ok quickly
// we assume it's ok and kill the process
// we don't need the actual build
const timeout = setTimeout(() => {
child.kill()
resolve()
}, timing)
}), maxTimeout)
35 changes: 35 additions & 0 deletions e2e-tests/__tests__/cli-args-unknow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
exec,
execOpts,
phenomic,
timing,
maxTimeout,
} from "./utils"

it("should throw if a CLI flag is NOT recognized",
() => new Promise((resolve, reject) => {
const child = exec(
`${ phenomic } start --open=false --lol`, execOpts,
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
const isUnknown = err.message.indexOf("Unknown argument") > -1
if (isUnknown) {
resolve()
return
}
console.log(err)
}
reject()
}
)

// server need to be killed manually
const timeout = setTimeout(
() => {
child.kill()
reject("Test didn't finish before timeout")
},
timing
)
}), maxTimeout)
Loading

0 comments on commit c13d849

Please sign in to comment.