Skip to content

Commit 2ec17c4

Browse files
committed
test: add demonstration
1 parent a1f0310 commit 2ec17c4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as fs from 'fs'
2+
import * as assert from 'assert'
3+
import * as cp from 'child_process'
4+
5+
describe('demo', function () {
6+
const temporaryDir = '/tmp/myTestDirectory'
7+
8+
it('test', async function () {
9+
// Create temporary dir and assert it exists.
10+
fs.mkdirSync(temporaryDir, { recursive: true })
11+
assert.ok(fs.existsSync(temporaryDir), 'does not exist directly after creating')
12+
13+
// Run a process that checks that it exists.
14+
const result = new Promise((resolve, reject) => {
15+
const proc = cp.spawn('ls', [temporaryDir])
16+
proc.on('exit', function (code) {
17+
resolve(code)
18+
})
19+
proc.stderr.on('data', function (data) {
20+
reject(data.toString())
21+
})
22+
})
23+
const r = await result
24+
// Assert that process found the file
25+
assert.strictEqual(r, 0, 'did not exit with 0')
26+
assert.ok(fs.existsSync(temporaryDir), 'does not exist after the test')
27+
fs.rmdirSync(temporaryDir, { recursive: true })
28+
})
29+
})

0 commit comments

Comments
 (0)