Skip to content

Commit 017f172

Browse files
TS2Swift tests: warn on export assignment
1 parent dd164d2 commit 017f172

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ exports[`ts2swift > snapshots Swift output for Documentation.d.ts > Documentatio
121121
"
122122
`;
123123

124+
exports[`ts2swift > snapshots Swift output for ExportAssignment.d.ts > ExportAssignment 1`] = `
125+
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
126+
// DO NOT EDIT.
127+
//
128+
// To update this file, just rebuild your project or run
129+
// \`swift package bridge-js\`.
130+
131+
@_spi(BridgeJS) import JavaScriptKit
132+
133+
@JSGetter var foo: Double
134+
"
135+
`;
136+
124137
exports[`ts2swift > snapshots Swift output for Interface.d.ts > Interface 1`] = `
125138
"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
126139
// DO NOT EDIT.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const foo: number;
2+
export default foo;

Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/ts2swift.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
import { describe, it, expect } from 'vitest';
2+
import { describe, it, expect, vi } from 'vitest';
33
import { readdirSync, mkdtempSync, writeFileSync, rmSync } from 'fs';
44
import { fileURLToPath } from 'url';
55
import path from 'path';
@@ -50,4 +50,19 @@ describe('ts2swift', () => {
5050
rmSync(tmpDir, { recursive: true, force: true });
5151
}
5252
});
53+
54+
it('emits a warning when export assignments cannot be generated', () => {
55+
const dtsPath = path.join(inputsDir, 'ExportAssignment.d.ts');
56+
const stderrSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
57+
try {
58+
run([dtsPath], { tsconfigPath, logLevel: 'warning' });
59+
const combined = stderrSpy.mock.calls.map(args => String(args[0])).join('');
60+
expect(combined).toMatch(/Skipping export assignment/);
61+
// Only warn once for the export assignment node
62+
const occurrences = (combined.match(/Skipping export assignment/g) || []).length;
63+
expect(occurrences).toBe(1);
64+
} finally {
65+
stderrSpy.mockRestore();
66+
}
67+
});
5368
});

0 commit comments

Comments
 (0)