This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make integration tests play nice with Jest
Rename /__tests__ --> /integration-tests
- Loading branch information
1 parent
b3238d7
commit 9d447e6
Showing
7 changed files
with
92 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters