-
Notifications
You must be signed in to change notification settings - Fork 269
/
runner-spec.js
116 lines (93 loc) · 3.33 KB
/
runner-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"use babel" // TODO
/* eslint-disable no-invalid-this */ import Runner from "../lib/runner"
import ScriptOptions from "../lib/script-options"
import path from "path"
describe("Runner", () => {
beforeEach(() => {
this.command = "node"
this.runOptions = new ScriptOptions()
this.runOptions.cmd = this.command
this.runner = new Runner(this.runOptions)
})
afterEach(() => {
this.runner.destroy()
})
describe("run", () => {
it("with no input", () => {
runs(() => {
this.output = null
this.runner.onDidWriteToStdout((output) => {
this.output = output
})
this.runner.run(this.command, ["./spec/fixtures/outputTest.js"], {})
})
waitsFor(() => this.output !== null, "File should execute", 2000)
runs(() => expect(this.output).toEqual({ message: "hello\n" }))
})
it("with an input string", () => {
runs(() => {
this.output = null
this.runner.onDidWriteToStdout((output) => {
this.output = output
})
this.runner.run(this.command, ["./spec/fixtures/ioTest.js"], {}, "hello")
})
waitsFor(() => this.output !== null, "File should execute", 2000)
runs(() => expect(this.output).toEqual({ message: "TEST: hello\n" }))
})
it("exits", () => {
runs(() => {
this.exited = false
this.runner.onDidExit(() => {
this.exited = true
})
this.runner.run(this.command, ["./spec/fixtures/outputTest.js"], {})
})
waitsFor(() => this.exited, "Should receive exit callback", 2000)
})
it("notifies about writing to stderr", () => {
runs(() => {
this.failedEvent = null
this.runner.onDidWriteToStderr((event) => {
this.failedEvent = event
})
this.runner.run(this.command, ["./spec/fixtures/throw.js"], {})
})
waitsFor(() => this.failedEvent, "Should receive failure callback", 2000)
runs(() => expect(this.failedEvent.message).toMatch(/kaboom/))
})
it("terminates stdin", () => {
runs(() => {
this.output = null
this.runner.onDidWriteToStdout((output) => {
this.output = output
})
this.runner.run(this.command, ["./spec/fixtures/stdinEndTest.js"], {}, "unused input")
})
waitsFor(() => this.output !== null, "File should execute", 2000)
runs(() => expect(this.output).toEqual({ message: "stdin terminated\n" }))
})
it("dirnameTest", () => {
runs(() => {
this.output = null
this.runner.onDidWriteToStdout((output) => {
this.output = output
})
this.runner.run(this.command, ["./spec/fixtures/dirnameTest.js"], {}, "unused input")
})
waitsFor(() => this.output !== null, "File should execute", 2000)
runs(() => expect(this.output).toEqual({ message: `__dirname ${path.resolve("./spec/fixtures")}\n` }))
})
it("folder with space", () => {
runs(() => {
this.output = null
this.runner.onDidWriteToStdout((output) => {
this.output = output
})
this.runner.run(this.command, ["./spec/fixtures/folder with space/test.js"], {}, "unused input")
})
waitsFor(() => this.output !== null, "File should execute", 2000)
runs(() => expect(this.output).toEqual({ message: `works\n` }))
})
})
})