forked from dfinity/icp-js-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasm-generate.test.ts
More file actions
66 lines (60 loc) · 2.45 KB
/
wasm-generate.test.ts
File metadata and controls
66 lines (60 loc) · 2.45 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
import { beforeAll, describe, expect, it } from 'vitest';
import { wasmGenerate } from '../src/core/generate/rs.ts';
import { testWasmInit } from './utils/wasm.ts';
const TESTS_ASSETS_DIR = './tests/assets';
const SNAPSHOTS_BASE_DIR = './snapshots/wasm-generate';
beforeAll(async () => {
await testWasmInit();
});
describe('wasmGenerate', () => {
describe('with rootExport: false', () => {
it.each(['hello_world', 'example'])('should generate a bindgen for %s', async (serviceName) => {
const didFile = `${TESTS_ASSETS_DIR}/${serviceName}.did`;
const snapshotsDir = `${SNAPSHOTS_BASE_DIR}/no-root-export`;
const result = wasmGenerate({
did_file: { LocalPath: didFile },
service_name: serviceName,
declarations: {
root_exports: false,
},
});
await expect(result.declarations_js).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/declarations/${serviceName}.did.js.snapshot`,
);
await expect(result.declarations_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/declarations/${serviceName}.did.d.ts.snapshot`,
);
await expect(result.interface_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/${serviceName}.d.ts.snapshot`,
);
await expect(result.service_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/${serviceName}.ts.snapshot`,
);
});
});
describe('with rootExport: true', () => {
it.each(['hello_world', 'example'])('should generate a bindgen for %s', async (serviceName) => {
const didFile = `${TESTS_ASSETS_DIR}/${serviceName}.did`;
const snapshotsDir = `${SNAPSHOTS_BASE_DIR}/root-export`;
const result = wasmGenerate({
did_file: { LocalPath: didFile },
service_name: serviceName,
declarations: {
root_exports: true,
},
});
await expect(result.declarations_js).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/declarations/${serviceName}.did.js.snapshot`,
);
await expect(result.declarations_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/declarations/${serviceName}.did.d.ts.snapshot`,
);
await expect(result.interface_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/${serviceName}.d.ts.snapshot`,
);
await expect(result.service_ts).toMatchFileSnapshot(
`${snapshotsDir}/${serviceName}/${serviceName}.ts.snapshot`,
);
});
});
});