Skip to content

Commit bfc7ad5

Browse files
committed
test: ensure exec tests run on OSX
This test suite was the last one relying on older test-paradigm.
1 parent 114199a commit bfc7ad5

File tree

2 files changed

+40
-92
lines changed

2 files changed

+40
-92
lines changed

spec/tests/exec.js

+39-91
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,48 @@
11
import { test } from 'tape'
2-
import yargs from 'yargs'
3-
import * as exec from '../../commands/exec.js'
4-
import { runPipe } from '../test.js'
5-
6-
const parser = yargs().scriptName('xst').command(exec).help().fail(false)
7-
8-
const execCmd = async (cmd, args) => {
9-
return await yargs()
10-
.scriptName('xst')
11-
.command(cmd)
12-
.fail(false)
13-
.parse(args)
14-
}
15-
16-
test('shows help', async function (t) {
17-
// Run the command module with --help as argument
18-
const output = await new Promise((resolve, reject) => {
19-
parser.parse(['execute', '--help'], (err, argv, output) => {
20-
if (err) { return reject(err) }
21-
resolve(output)
22-
})
23-
})
24-
const firstLine = output.split('\n')[0]
2+
import { run, runPipe } from '../test.js'
3+
4+
test("calling 'xst execute --help'", async (t) => {
5+
const { stderr, stdout } = await run('xst', ['execute', '--help'])
6+
if (stderr) { return t.fail(stderr) }
7+
8+
const firstLine = stdout.split('\n')[0]
259

2610
t.equal(firstLine, 'xst execute [<query>] [options]', firstLine)
11+
t.end()
2712
})
2813

29-
test('executes command', async function (t) {
30-
const argv = await new Promise((resolve, reject) => {
31-
parser.parse(['execute', '1+1'], (err, argv, output) => {
32-
if (err) { return reject(err) }
33-
resolve(argv)
34-
})
35-
})
14+
test('executes command', async (t) => {
15+
const { stderr, stdout } = await run('xst', ['execute', '1+1'])
16+
if (stderr) { return t.fail(stderr) }
3617

37-
t.equal(argv.query, '1+1')
18+
t.equal(stdout, '2\n')
3819
})
3920

4021
test('executes command with alias \'exec\'', async function (t) {
41-
const argv = await new Promise((resolve, reject) => {
42-
parser.parse(['exec', '1+1'], (err, argv, output) => {
43-
if (err) { return reject(err) }
44-
resolve(argv)
45-
})
46-
})
47-
48-
t.equal(argv.query, '1+1')
22+
const { stderr, stdout } = await run('xst', ['exec', '1+1'])
23+
if (stderr) { return t.fail(stderr) }
24+
25+
t.equal(stdout, '2\n')
4926
})
5027

5128
test('executes command with alias \'run\'', async function (t) {
52-
const argv = await new Promise((resolve, reject) => {
53-
parser.parse(['run', '1+1'], (err, argv, output) => {
54-
if (err) { return reject(err) }
55-
resolve(argv)
56-
})
57-
})
58-
59-
t.equal(argv.query, '1+1')
29+
const { stderr, stdout } = await run('xst', ['run', '1+1'])
30+
if (stderr) { return t.fail(stderr) }
31+
32+
t.equal(stdout, '2\n')
6033
})
6134

6235
test('executes bound command', async function (t) {
63-
const argv = await new Promise((resolve, reject) => {
64-
parser.parse(['exec', '-b', '{"a":1}', '$a+$a'], (err, argv, output) => {
65-
if (err) { return reject(err) }
66-
resolve(argv)
67-
})
68-
})
69-
t.plan(2)
70-
t.equal(argv.query, '$a+$a')
71-
t.equal(argv.bind.a, 1)
36+
const { stderr, stdout } = await run('xst', ['execute', '-b', '{"a":1}', '$a+$a'])
37+
if (stderr) { return t.fail(stderr) }
38+
39+
t.equal(stdout, '2\n')
7240
})
7341

7442
test('bind parse error', async function (t) {
75-
try {
76-
const res = await execCmd(exec, ['exec', '-b', '{a:1}', '$a+$a'])
77-
t.notOk(res)
78-
} catch (e) {
79-
t.ok(e, e)
80-
}
43+
const { stderr, stdout } = await run('xst', ['execute', '-b', '{a:1}', '$a+$a'])
44+
t.notOk(stdout)
45+
t.ok(stderr, stderr)
8146
})
8247

8348
test('read bind from stdin', async function (t) {
@@ -87,44 +52,27 @@ test('read bind from stdin', async function (t) {
8752
})
8853

8954
test('cannot read bind from stdin', async function (t) {
90-
try {
91-
const res = await execCmd(exec, ['exec', '-b', '-', '$a+$a'])
92-
t.fail(res)
93-
} catch (e) {
94-
t.ok(e, e)
95-
}
55+
const { stderr, stdout } = await run('xst', ['execute', '-b', '-', '$a+$a'])
56+
if (stdout) { return t.fail(stdout) }
57+
t.ok(stderr, stderr)
9658
})
9759

9860
test('cannot read query file from stdin', async function (t) {
99-
try {
100-
const res = await execCmd(exec, ['exec', '-f', '-'])
101-
t.fail(res)
102-
} catch (e) {
103-
t.ok(e, e)
104-
}
61+
const { stderr, stdout } = await run('xst', ['execute', '-f', '-'])
62+
if (stdout) { return t.fail(stdout) }
63+
t.ok(stderr, stderr)
10564
})
10665

10766
test('read query file', async function (t) {
108-
try {
109-
const argv = await new Promise((resolve, reject) => {
110-
parser.parse(['exec', '-f', './spec/fixtures/test.xq'], (err, argv, output) => {
111-
if (err) { return reject(err) }
112-
resolve(argv)
113-
})
114-
})
115-
t.equals(argv.f, 'spec/fixtures/test.xq', 'should be normalized')
116-
} catch (e) {
117-
t.notOk(e, e)
118-
}
67+
const { stderr, stdout } = await run('xst', ['execute', '-f', './spec/fixtures/test.xq'])
68+
if (stderr) { return t.fail(stderr) }
69+
t.ok(stdout, stdout)
11970
})
12071

12172
test('read query file with query', async function (t) {
122-
try {
123-
const argv = await parser.parse(['exec', '-f', 'spec/fixtures/test.xq', '1+1'])
124-
t.fail(argv, 'Should not return a result')
125-
} catch (e) {
126-
t.ok(e, e)
127-
}
73+
const { stderr, stdout } = await run('xst', ['execute', '-f', './spec/fixtures/test.xq', '1+1'])
74+
if (stdout) { return t.fail(stdout) }
75+
t.ok(stderr, stderr)
12876
})
12977

13078
test('read file from stdin', async function (t) {

spec/tests/list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ test('with fixtures uploaded', async (t) => {
297297
/db/list-test/tests/info.js
298298
/db/list-test/tests/cli.js
299299
/db/list-test/tests/upload.js
300-
/db/list-test/tests/configuration.js
301300
/db/list-test/tests/exec.js
301+
/db/list-test/tests/configuration.js
302302
/db/list-test/tests/rm.js
303303
/db/list-test/tests/get.js
304304
/db/list-test/tests/list.js

0 commit comments

Comments
 (0)