forked from cdklabs/jsii-srcmak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.test.ts
More file actions
116 lines (94 loc) · 3.14 KB
/
cli.test.ts
File metadata and controls
116 lines (94 loc) · 3.14 KB
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
import { execFileSync } from 'child_process';
import * as path from 'path';
import * as fs from 'fs-extra';
import { mkdtemp } from '../src/util';
import { snapshotDirectory } from './util';
const program = require.resolve('../bin/jsii-srcmak');
const srcdir = path.join(__dirname, '..', 'example');
jest.setTimeout(60_000); // 1min
test('no arguments - fails with help', () => {
expect(() => srcmakcli()).toThrow(/Invalid number of arguments. expecting a single positional argument./);
});
test('invalid entrypoint', () => {
expect(() => srcmakcli(srcdir)).toThrow(/unable to find typescript entrypoint/);
});
test('compile only', () => {
srcmakcli(
srcdir,
'--entrypoint lib/main.ts',
);
});
test('jsii output', async () => {
await mkdtemp(async dir => {
const jsiiPath = path.join(dir, 'my.jsii');
srcmakcli(srcdir,
'--entrypoint lib/main.ts',
`--jsii-path ${jsiiPath}`,
);
expect(JSON.parse(fs.readFileSync(jsiiPath, 'utf-8'))).toMatchSnapshot();
});
});
test('fails if only one python option is given', () => {
expect(() => srcmakcli(srcdir,
'--entrypoint lib/main.ts',
'--python-module-name module',
)).toThrow(/--python-outdir is required if --python-module-name is specified/);
expect(() => srcmakcli(srcdir,
'--entrypoint lib/main.ts',
'--python-outdir dir',
)).toThrow(/--python-module-name is required if --python-outdir is specified/);
});
test('fails if only one java option is given', () => {
expect(() => srcmakcli(srcdir,
'--entrypoint lib/main.ts',
'--java-package mypackage',
)).toThrow(/--java-outdir is required/);
expect(() => srcmakcli(srcdir,
'--entrypoint lib/main.ts',
'--java-outdir dir',
)).toThrow(/--java-package is required/);
});
test('python output', async () => {
await mkdtemp(async tmpdir => {
// put under a non-existent directory to verify it is created
const outdir = path.join(tmpdir, 'python');
srcmakcli(srcdir,
'--entrypoint lib/main.ts',
`--python-outdir ${outdir}`,
'--python-module-name my.python.module',
);
expect(await snapshotDirectory(outdir, {
excludeFiles: [ '@0.0.0.jsii.tgz' ],
})).toMatchSnapshot();
});
});
test('java output', async () => {
await mkdtemp(async tmpdir => {
// put under a non-existent directory to verify it is created
const outdir = path.join(tmpdir, 'java');
srcmakcli(srcdir,
'--entrypoint lib/main.ts',
`--java-outdir ${outdir}`,
'--java-package mypackage',
);
expect(await snapshotDirectory(outdir, {
excludeLines: [ /.*@javax.annotation.Generated.*/ ],
excludeFiles: [ '@0.0.0.jsii.tgz' ],
})).toMatchSnapshot();
});
});
test('dependencies', async () => {
await mkdtemp(async srcdir => {
await fs.writeFile(path.join(srcdir, 'index.ts'), `
import * as fs from 'fs';
fs.writeFileSync('foo.bar', 'hello');
`);
// resolve against *this* executable
const dep = path.dirname(require.resolve('@types/node/package.json'));
srcmakcli(srcdir, `--dep ${dep}`);
});
});
function srcmakcli(...args: string[]) {
const a = args.join(' ');
execFileSync(program, a ? a.split(' ') : []);
}