forked from cdklabs/jsii-srcmak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrcmak.test.ts
More file actions
150 lines (129 loc) · 3.78 KB
/
srcmak.test.ts
File metadata and controls
150 lines (129 loc) · 3.78 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import * as fs from 'fs-extra';
import * as path from 'path';
import { snapshotDirectory } from './util';
import { srcmak } from '../src';
import { mkdtemp } from '../src/util';
jest.setTimeout(60_000); // 1min
test('just compile', async () => {
await mkdtemp(async source => {
await fs.writeFile(path.join(source, 'index.ts'), `
export interface Operands {
readonly lhs: number;
readonly rhs: number;
}
export class Hello {
public add(ops: Operands): number {
return ops.lhs + ops.rhs;
}
}
`);
await srcmak(source);
});
});
test('compilation error fails and includes error message', async () => {
await mkdtemp(async source => {
await fs.writeFile(path.join(source, 'index.ts'), 'I DO NOT COMPUTE');
let error;
try { await srcmak(source); }
catch (e) { error = e; }
expect(error).toBeDefined();
expect(error.message).toMatch(/Cannot find name 'COMPUTE'/);
expect(error.message).toMatch(/Compilation errors prevented the JSII assembly/);
});
});
test('python + different entrypoint + submodule', async () => {
await mkdtemp(async source => {
const entry = 'different/entry.ts';
const ep = path.join(source, entry);
await fs.mkdirp(path.dirname(ep));
await fs.writeFile(ep, `
export interface Operands {
readonly lhs: number;
readonly rhs: number;
}
export class Hello {
public add(ops: Operands): number {
return ops.lhs + ops.rhs;
}
}
`);
await mkdtemp(async target => {
await srcmak(source, {
entrypoint: 'different/entry.ts',
packageName: 'python.package',
python: {
outdir: target,
moduleName: 'my-python_module.submodule',
},
});
const dir = await snapshotDirectory(target, {
excludeFiles: [ 'generated@0.0.0.jsii.tgz' ],
});
expect(dir).toMatchSnapshot();
});
});
});
test('java + different entrypoint', async () => {
await mkdtemp(async source => {
const entry = 'different/entry.ts';
const ep = path.join(source, entry);
await fs.mkdirp(path.dirname(ep));
await fs.writeFile(ep, `
export interface Operands {
readonly lhs: number;
readonly rhs: number;
}
export class Hello {
public add(ops: Operands): number {
return ops.lhs + ops.rhs;
}
}
`);
await mkdtemp(async target => {
await srcmak(source, {
entrypoint: 'different/entry.ts',
packageName: 'java.package',
java: {
outdir: target,
package: 'hello.world',
},
});
const dir = await snapshotDirectory(target, {
excludeLines: [ /.*@javax.annotation.Generated.*/ ],
excludeFiles: [ 'generated@0.0.0.jsii.tgz' ],
});
expect(dir).toMatchSnapshot();
});
});
});
test('deps: compile against a local jsii dependency', async () => {
await mkdtemp(async source => {
await fs.writeFile(path.join(source, 'index.ts'), `
import { Construct } from 'constructs';
export class Hello extends Construct {
public add(lhs: number, rhs: number): number {
return lhs + rhs;
}
}
`);
await srcmak(source, {
deps: [
path.dirname(require.resolve('constructs/package.json')), // <<---- this is the magic
],
});
});
});
test('outputJsii can be used to look at the jsii file', async () => {
await mkdtemp(async source => {
await fs.writeFile(path.join(source, 'index.ts'), `
export class Foo {
public static hello() { return "world"; }
}
`);
await mkdtemp(async target => {
const outputPath = path.join(target, '.jsii');
await srcmak(source, { jsii: { path: outputPath } });
expect(await fs.readJson(outputPath)).toMatchSnapshot();
});
})
});