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 authored and MoOx committed Oct 25, 2016
1 parent 5509369 commit 1af9ab4
Show file tree
Hide file tree
Showing 61 changed files with 482 additions and 490 deletions.
4 changes: 2 additions & 2 deletions __tests__/index.js → __tests__/build-result.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFileSync } from "fs"
import { join } from "path"

import test from "ava"
import test from "jest-ava-api"
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
131 changes: 67 additions & 64 deletions __tests__/cli.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,87 @@
import { join } from "path"
import { exec } from "child_process"

import test from "ava"
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

test.cb("should throw if a CLI flag is NOT recognized", (t) => {
const child = exec(
`${ phenomic } start --open=false --lol`, execOpts,
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
t.truthy(err.message.indexOf("Unknown argument") > -1)
t.end()
}
}
)
describe("Integration: CLI", () => {
beforeEach(() => {
process.env.BABEL_ENV = "development"
})

const timeout = setTimeout(() => {
child.kill()
t.fail()
t.end()
}, timing)
})
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()
}
}
)

test.cb("should NOT throw if a CLI flag is recognized", (t) => {
const child = exec(
`${ phenomic } start --open=false --devPort=4000`, execOpts,
const timeout = setTimeout(() => {
child.kill()
reject("Test didn't finish before timeout")
}, timing)
})
})

// should die quickly...
(err) => {
if (err && !err.killed) {
console.log(err)
clearTimeout(timeout)
t.fail()
t.end()
}
}
)
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,

// ...or be ok quickly
// (so we assume it's ok and kill the process, we don't need the actual build)
const timeout = setTimeout(() => {
child.kill()
t.pass()
t.end()
}, timing)
})
// should die quickly...
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)

test.cb("should NOT throw if port is used", (t) => {
const app = require("express")()
// ...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)
})
})

const server = app.listen(8081, (err) => {
if (err) {
t.fail()
t.end()
}
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=8081`, execOpts,
const child = exec(
`${ phenomic } start --open=false --devPort=3333`, execOpts,

(err) => {
if (err && !err.killed) {
console.log(err)
clearTimeout(timeout)
t.fail()
t.end()
}
}
)
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)

const timeout = setTimeout(() => {
child.kill()
server.close()
t.pass()
t.end()
}, timing * 2)
const timeout = setTimeout(() => {
child.kill()
server.close()
resolve()
}, timing * 2)
})
})
})
})
7 changes: 7 additions & 0 deletions __tests__/jest-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"testRegex": "__tests__/.*\\.js$",
"setupTestFrameworkScriptFile": "<rootDir>/scripts/jest-framework-setup.js",
"testPathDirs": [
"__tests__"
]
}
7 changes: 7 additions & 0 deletions integration-tests/jest-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"testRegex": "__tests__/.*\\.js$",
"setupTestFrameworkScriptFile": "<rootDir>/scripts/jest-framework-setup.js",
"testPathDirs": [
"__tests__"
]
}
58 changes: 24 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"yargs": "^4.3.1"
},
"devDependencies": {
"ava": "^0.16.0",
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-eslint": "^7.0.0",
Expand All @@ -107,21 +106,21 @@
"expect": "^1.13.4",
"expect-jsx": "^2.2.1",
"flow-bin": "^0.32.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 @@ -153,9 +152,9 @@
"lint:js:flow": "flow check",
"lint:js": "npm-run-all --parallel lint:js:*",
"lint": "npm-run-all --parallel lint:*",
"tests": "ava",
"tests": "cross-env TESTING=1 jest",
"#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 __tests__/jest-config.json",
"phenomic-theme-base": "babel-node scripts/phenomic-theme-base.js",
"phenomic-theme-base-linting": "eslint --config package.json --ignore-path .gitignore --fix themes/phenomic-theme-base/scripts themes/phenomic-theme-base/src",
"prephenomic-theme-base-start": "npm run transpile && npm run phenomic-theme-base",
Expand All @@ -177,24 +176,14 @@
"predocs-deploy": "cd docs && npm run showcase-screenshots && npm run build",
"docs-deploy": "cd docs && ./scripts/deploy.sh",
"preall-tests": "npm run transpile && npm run lint",
"all-tests": "cross-env TESTING=1 npm run tests && npm run phenomic-theme-base && npm run phenomic-theme-base-linting && npm run test-phenomic-theme-base && npm run test-docs",
"all-tests": "cross-env TESTING=1 npm run tests && npm run phenomic-theme-base && npm run phenomic-theme-base-linting && npm run test-phenomic-theme-base",
"test": "npm run all-tests",
"posttest": "npm run test-docs",
"test-with-coverage": "nyc --check-coverage --lines 70 npm run all-tests",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"coverage": "coveralls",
"release": "npmpub",
"postrelease": "npm run docs-deploy"
},
"nyc": {
"exclude": [
"**/__tests__/**",
"**.template.js"
],
"include": [
"src/**"
],
"sourceMap": false,
"instrument": false
},
"babel": {
"presets": [
"babel-preset-latest",
Expand All @@ -203,21 +192,17 @@
],
"plugins": [
"babel-plugin-flow-react-proptypes"
],
"env": {
"test": {
"plugins": [
"babel-plugin-istanbul"
]
}
}
]
},
"eslintConfig": {
"root": true,
"parser": "babel-eslint",
"extends": [
"eslint-config-i-am-meticulous/react-flow"
],
"env": {
"jest": true
},
"rules": {
"import/max-dependencies": [
2,
Expand All @@ -234,15 +219,20 @@
"stylelint": {
"extends": "stylelint-config-standard"
},
"ava": {
"files": [
"src/**/__tests__/*.js"
"jest": {
"preprocessorIgnorePatterns": [
"node_modules"
],
"testPathIgnorePatterns": [
"/fixtures/",
"/results/",
"/stub/",
"/_output/"
],
"failFast": true,
"verbose": true,
"require": [
"babel-register"
"testPathDirs": [
"src"
],
"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
18 changes: 9 additions & 9 deletions src/Link/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava"
import test from "jest-ava-api"
import React, { createElement } from "react"
import { createRenderer } from "react-addons-test-utils"
import expect from "expect"
Expand Down Expand Up @@ -50,7 +50,7 @@ test("should allow passing props to <a> tag", () => {
{
to: "/",
className: "foo",
foo: "bar",
disabled: true,
children: <span />,
},
),
Expand All @@ -64,7 +64,7 @@ test("should allow passing props to <a> tag", () => {
expect(renderer(component)).toEqualJSX(
<a
className="foo"
foo="bar"
disabled
onClick={ function noRefCheck() {} }
style={{ }}
>
Expand All @@ -81,7 +81,7 @@ test("should have activeClassName when url matched", () => {
to: "/",
className: "foo",
activeClassName: "bar",
foo: "bar",
disabled: true,
children: <span />,
},
),
Expand All @@ -95,7 +95,7 @@ test("should have activeClassName when url matched", () => {
expect(renderer(component)).toEqualJSX(
<a
className="foo bar"
foo="bar"
disabled
onClick={ function noRefCheck() {} }
style={{ }}
>
Expand All @@ -112,7 +112,7 @@ test("should have activeClassName when url matched with index.html", () => {
to: "/",
className: "foo",
activeClassName: "bar",
foo: "bar",
disabled: true,
children: <span />,
},
),
Expand All @@ -126,7 +126,7 @@ test("should have activeClassName when url matched with index.html", () => {
expect(renderer(component)).toEqualJSX(
<a
className="foo bar"
foo="bar"
disabled
onClick={ function noRefCheck() {} }
style={{ }}
>
Expand All @@ -142,7 +142,7 @@ test("should not have undefined when no activeClassName props", () => {
{
to: "/",
className: "foo",
foo: "bar",
disabled: true,
children: <span />,
},
),
Expand All @@ -156,7 +156,7 @@ test("should not have undefined when no activeClassName props", () => {
expect(renderer(component)).toEqualJSX(
<a
className="foo"
foo="bar"
disabled
onClick={ function noRefCheck() {} }
style={{ }}
>
Expand Down
2 changes: 1 addition & 1 deletion src/_utils/beautify-html/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava"
import test from "jest-ava-api"

import beautifyHTML from ".."

Expand Down
Loading

0 comments on commit 1af9ab4

Please sign in to comment.