-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathts2swift.test.js
More file actions
41 lines (35 loc) · 1.31 KB
/
ts2swift.test.js
File metadata and controls
41 lines (35 loc) · 1.31 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
// @ts-check
import { describe, it, expect } from 'vitest';
import { readdirSync } from 'fs';
import { fileURLToPath } from 'url';
import path from 'path';
import { run } from '../src/cli.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/** Path to BridgeJSToolTests/Inputs/TypeScript (.d.ts fixtures and tsconfig). */
const inputsDir = path.resolve(__dirname, 'fixtures');
const tsconfigPath = path.join(inputsDir, 'tsconfig.json');
function runTs2Swift(dtsPath) {
return run([dtsPath], { tsconfigPath, logLevel: 'error' });
}
function collectDtsInputs() {
const entries = readdirSync(inputsDir, { withFileTypes: true });
return entries
.filter((e) => e.isFile() && e.name.endsWith('.d.ts'))
.map((e) => e.name)
.sort();
}
describe('ts2swift', () => {
const dtsFiles = collectDtsInputs();
if (dtsFiles.length === 0) {
it.skip('no .d.ts fixtures found in BridgeJSToolTests/Inputs', () => {});
return;
}
for (const dtsFile of dtsFiles) {
it(`snapshots Swift output for ${dtsFile}`, () => {
const dtsPath = path.join(inputsDir, dtsFile);
const swiftOutput = runTs2Swift(dtsPath);
const name = dtsFile.replace(/\.d\.ts$/, '');
expect(swiftOutput).toMatchSnapshot(name);
});
}
});