Skip to content

Commit

Permalink
test: 🚨 updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Mar 3, 2020
1 parent a771ec6 commit ff9e055
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
17 changes: 10 additions & 7 deletions __tests__/runner-spawn.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HASH_FILE } from "./../src/build"
import fs from "fs"
import { Runner } from "../src/runner"
import sinon from "sinon"
import chai from "chai"
Expand All @@ -18,6 +20,7 @@ chalk.level = 0

beforeEach(() => {
sinon.resetHistory()
if (fs.existsSync(HASH_FILE)) fs.unlinkSync(HASH_FILE)
})

afterAll(() => {
Expand All @@ -26,7 +29,7 @@ afterAll(() => {
})

test("failed command", async () => {
const runner = new Runner({ fancy: true })
const runner = new Runner({ pretty: true })
const spawn = sinon.stub(runner, "spawn").rejects()
await runner.run("test", { scripts: { test: "fail" } })
spawn.should.be.calledWith("fail", [])
Expand All @@ -40,7 +43,7 @@ test("formatDuration", () => {
})

test("error", async () => {
const runner = new Runner({ fancy: true })
const runner = new Runner({ pretty: true })
await runner.run("test", { scripts: { test: "false", pretest: "false" } })
stubs.exit.should.be.calledWith(1)
})
Expand All @@ -53,25 +56,25 @@ test("string error", async () => {
})

test("error --silent", async () => {
const runner = new Runner({ fancy: false, silent: true })
const runner = new Runner({ pretty: false, silent: true })
await runner.run("false", {})
stubs.exit.should.be.calledWith(1)
})

test("unknown command", async () => {
const runner = new Runner({ fancy: false })
const runner = new Runner({ pretty: false })
await runner.run("foobar", {})
stubs.exit.should.be.calledWith(1)
})

test("warning", async () => {
const runner = new Runner({ fancy: true })
const runner = new Runner({ pretty: true })
await runner.run("echo warning", {})
stubs.write.should.be.calledWithMatch("⚠")
})

test("--no-fancy", async () => {
const runner = new Runner({ fancy: false })
test("--no-pretty", async () => {
const runner = new Runner({ pretty: false })
await runner.run("echo foobar", {})
stubs.log.should.be.calledWithMatch("foobar")
})
21 changes: 12 additions & 9 deletions __tests__/runner.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Runner } from "../src/runner"
import sinon from "sinon"
import { HASH_FILE } from "./../src/build"
import chai from "chai"
import sinonChai from "sinon-chai"
import chalk from "chalk"
import { PackageJson } from "../src/workspace"
import fs from "fs"
import * as path from "path"
import sinon from "sinon"
import sinonChai from "sinon-chai"
import { defaults } from "../src/options"
import { Runner } from "../src/runner"
import { PackageJson } from "../src/workspace"

chai.use(sinonChai)
chai.should()
Expand All @@ -21,6 +24,7 @@ chalk.level = 0

beforeEach(() => {
sinon.resetHistory()
if (fs.existsSync(HASH_FILE)) fs.unlinkSync(HASH_FILE)
})

afterAll(() => {
Expand All @@ -43,8 +47,7 @@ const advancedPackage: PackageJson = {
}

test("constructor", () => {
chai.expect(new Runner({}).options).to.be.empty
chai.expect(new Runner({ parallel: true }).options.concurrent).to.be.true
chai.expect(new Runner({}).options).to.be.deep.equal(defaults)
})

test("advanced build --dry-run", async () => {
Expand All @@ -53,7 +56,7 @@ test("advanced build --dry-run", async () => {
chai.expect(stubs.spawn).not.to.be.called
})

test("advanced build --no-fancy", async () => {
test("advanced build --no-pretty", async () => {
const runner = new Runner()
await runner.run("build", advancedPackage)

Expand Down Expand Up @@ -100,8 +103,8 @@ test("advanced build --no-fancy", async () => {
)
})

test("advanced build --fancy", async () => {
const runner = new Runner({ fancy: true })
test("advanced build --pretty", async () => {
const runner = new Runner({ pretty: true })
await runner.run("build", advancedPackage)

stubs.write.should.be.calledWithMatch("✔")
Expand Down

0 comments on commit ff9e055

Please sign in to comment.