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

Commit

Permalink
Use Jest as test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
thangngoc89 committed Sep 15, 2016
1 parent 8e0040d commit d7030ba
Show file tree
Hide file tree
Showing 64 changed files with 868 additions and 923 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ coverage
lib

# tests results
**/__tests__/_output*
**/__tests__/output*

# docs
docs/**/*.mov
Expand Down
2 changes: 2 additions & 0 deletions .lgtm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
approvals = 1
pattern = "(?i):shipit:|:\\+1:|LGTM"
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ before_install:
# remove useless/non listed deps
- npm prune

script: npm run test-with-coverage
script: npm run all-tests

after_success: npm run coverage
84 changes: 0 additions & 84 deletions __tests__/cli.js

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions __tests__/index.js → integration-tests/build-result.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from "ava"
import test from "jest-ava-api"

import { readFileSync } from "fs"
import { join } from "path"

import globby from "globby"

const testFolder = "../test-phenomic-theme-base/dist"
const testFolder = __dirname + "/../test-phenomic-theme-base/dist"
const files = globby.sync("**/*", {
cwd: testFolder,
nodir: true,
Expand Down
87 changes: 87 additions & 0 deletions integration-tests/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { join } from "path"

import { exec } from "child_process"

const target = join(__dirname, "..", "test-phenomic-theme-base")
const execOpts = { cwd: target }

const phenomic = "node ./node_modules/.bin/phenomic"
const timing = process.env.CI ? 10000 : 5000

describe("Integration: CLI", () => {
beforeEach(() => {
process.env.BABEL_ENV = "development"
})

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

const timeout = setTimeout(() => {
child.kill()
reject("Test didn't finish before timeout")
}, timing)
})
})

it("should NOT throw if a CLI flag is recognized", () => {
return 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)
})
})

it("should NOT throw if port is used", () => {
return 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)
}
}
)

const timeout = setTimeout(() => {
child.kill()
server.close()
resolve()
}, timing * 2)
})
})
})
})
58 changes: 21 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"yargs": "^4.3.1"
},
"devDependencies": {
"ava": "^0.16.0",
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-eslint": "^6.1.2",
Expand All @@ -105,21 +104,21 @@
"expect-jsx": "^2.2.1",
"flow-bin": "^0.31.1",
"image-optim": "^3.0.0",
"jest": "^15.1.1",
"jest-ava-api": "^0.1.0",
"js-beautify": "^1.5.10",
"jsdom": "^9.2.0",
"lnfs": "^3.0.0",
"mock-fs": "^3.9.0",
"npm-run-all": "^3.0.0",
"npmpub": "^3.0.0",
"nyc": "^8.1.0",
"react": "^15.0.0-rc.1",
"react-addons-test-utils": "^15.0.0-rc.1",
"react-dom": "^15.0.0-rc.1",
"react-helmet": "^3.0.0",
"react-redux": "^4.0.0",
"react-router": "^2.3.0",
"redux": "^3.0.0",
"sinon": "^1.17.3",
"stylelint": "^7.2.0",
"stylelint-config-standard": "^13.0.0",
"suppose": "^0.6.1"
Expand Down Expand Up @@ -175,9 +174,7 @@
"lint:js:flow": "flow check",
"lint:js": "npm-run-all --parallel lint:js:*",
"lint": "npm-run-all --parallel lint:*",
"tests": "ava",
"#integration-tests": "needs this order (index test the build, and cli is cleaning it)",
"integration-tests": "ava __tests__/index.js && ava __tests__/cli.js",
"integration-tests": "jest --config '{\"testRegex\": \"integration-tests\", \"setupTestFrameworkScriptFile\": \"<rootDir>/scripts/jest-framework-setup.js\"}'",
"pretest-phenomic-theme-base": "npm run transpile",
"test-phenomic-theme-base": "babel-node scripts/test-phenomic-theme-base.js",
"posttest-phenomic-theme-base": "npm run integration-tests",
Expand All @@ -189,24 +186,13 @@
"prephenomic-theme-base-start": "npm -s run transpile && babel-node scripts/phenomic-theme-base.js",
"phenomic-theme-base-start": "cd themes/phenomic-theme-base && npm start",
"preall-tests": "npm run lint",
"all-tests": "cross-env TESTING=1 npm run tests && npm run test-phenomic-theme-base && npm run docs",
"test": "npm run all-tests",
"test-with-coverage": "nyc --check-coverage --lines 70 npm run all-tests",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"all-tests": "cross-env TESTING=1 jest --coverage",
"postall-tests": "npm run test-phenomic-theme-base && npm run docs",
"test": "cross-env TESTING=1 jest",
"coverage": "coveralls",
"release": "npmpub",
"postrelease": "npm -s run docs-deploy"
},
"nyc": {
"exclude": [
"**/__tests__/**",
"**.template.js"
],
"include": [
"src/**"
],
"sourceMap": false,
"instrument": false
},
"babel": {
"presets": [
"babel-preset-es2015",
Expand All @@ -215,14 +201,7 @@
],
"plugins": [
"babel-plugin-flow-react-proptypes"
],
"env": {
"test": {
"plugins": [
"babel-plugin-istanbul"
]
}
}
]
},
"eslintConfig": {
"root": true,
Expand All @@ -232,21 +211,26 @@
],
"rules": {
"react/prefer-stateless-function": 0
},
"env": {
"jest": true
}
},
"eslintConfigRuleReact/prefer-stateless-function": "https://github.com/MoOx/phenomic/issues/46",
"stylelint": {
"extends": "stylelint-config-standard"
},
"ava": {
"files": [
"src/**/__tests__/*.js"
"jest": {
"preprocessorIgnorePatterns": [
"node_modules"
],
"failFast": true,
"verbose": true,
"require": [
"babel-register"
"testPathIgnorePatterns": [
"/fixtures/",
"/results/",
"/stub/",
"/output/"
],
"babel": "inherit"
"setupTestFrameworkScriptFile": "<rootDir>/scripts/jest-framework-setup.js",
"testEnvironment": "node"
}
}
2 changes: 2 additions & 0 deletions scripts/jest-framework-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000 // 30s
Loading

0 comments on commit d7030ba

Please sign in to comment.