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

Commit

Permalink
Make integration tests play nice with Jest
Browse files Browse the repository at this point in the history
Rename /__tests__ --> /integration-tests
  • Loading branch information
thangngoc89 committed Sep 14, 2016
1 parent b3238d7 commit 9d447e6
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 92 deletions.
84 changes: 0 additions & 84 deletions __tests__/cli.js

This file was deleted.

File renamed without changes.
5 changes: 5 additions & 0 deletions integration-tests/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This weird trick was used to make sure jest will run
// build result test from cli test since cli will clean up dist folder

require("../build-result.js")
require("../cli.js")
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
83 changes: 83 additions & 0 deletions integration-tests/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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", () => {
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)
})
})

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

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

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

const timeout = setTimeout(() => {
child.kill()
server.close()
resolve()
}, timing * 2)
})
})
})
})
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@
"lint:js:flow": "flow check",
"lint:js": "npm-run-all --parallel lint:js:*",
"lint": "npm-run-all --parallel lint:*",
"#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 integration-tests",
"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 Down Expand Up @@ -224,9 +223,6 @@
"preprocessorIgnorePatterns": [
"node_modules"
],
"testPathDirs": [
"src"
],
"testPathIgnorePatterns": [
"/fixtures/",
"/results/",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/setup/questions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validUrl from "valid-url"

export const defaultTestAnswers = {
name: "Phenomic",
name: "Phenomic_app",
homepage: "https://phenomic.io/",
twitter: "Phenomic_app",
CNAME: false,
Expand Down

0 comments on commit 9d447e6

Please sign in to comment.