-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ts root pathing distinctions (#370)
- Loading branch information
1 parent
1d778d7
commit 09d7eb9
Showing
4 changed files
with
65 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import { | |
opt, | ||
print, | ||
parse, | ||
componentWit, | ||
componentNew, | ||
componentEmbed, | ||
metadataShow, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package test:issue; | ||
|
||
interface types { | ||
record bar { | ||
x: u32 | ||
} | ||
} | ||
|
||
world issue { | ||
use types.{bar}; | ||
export foo: func() -> bar; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,53 @@ | ||
import { exec } from './helpers.js'; | ||
import { strictEqual } from 'node:assert'; | ||
import { exec } from "./helpers.js"; | ||
import { strictEqual } from "node:assert"; | ||
import { | ||
transpile, | ||
componentNew, | ||
componentEmbed, | ||
} from "../src/api.js"; | ||
import { readFile } from "node:fs/promises"; | ||
import { ok } from "node:assert"; | ||
|
||
const tscPath = 'node_modules/typescript/bin/tsc'; | ||
const tscPath = "node_modules/typescript/bin/tsc"; | ||
|
||
// always do TS generation | ||
let promise; | ||
export function tsGenerationPromise() { | ||
if (promise) return promise; | ||
return promise = (async () => { | ||
var { stderr } = await exec(tscPath, '-p', 'test/tsconfig.json'); | ||
strictEqual(stderr, ''); | ||
})(); | ||
return (promise = (async () => { | ||
var { stderr } = await exec(tscPath, "-p", "test/tsconfig.json"); | ||
strictEqual(stderr, ""); | ||
})()); | ||
} | ||
|
||
// TypeScript tests _must_ run after all codegen to complete successfully | ||
// This is due to type checking against generated bindings | ||
export function tsTest () { | ||
export function tsTest() { | ||
suite(`TypeScript`, () => { | ||
test('Verify Typescript output', async () => { | ||
test("Verify Typescript output", async () => { | ||
await tsGenerationPromise(); | ||
}); | ||
|
||
test(`TS aliasing`, async () => { | ||
const component = await componentNew( | ||
await componentEmbed({ | ||
witSource: await readFile( | ||
`test/fixtures/wits/issue-365/issue-365.wit`, | ||
"utf8" | ||
), | ||
dummy: true, | ||
}) | ||
); | ||
|
||
const { files } = await transpile(component, { name: "issue" }); | ||
|
||
const dtsSource = new TextDecoder().decode(files["issue.d.ts"]); | ||
|
||
ok( | ||
dtsSource.includes( | ||
`import type { Bar } from './interfaces/test-issue-types.js';` | ||
) | ||
); | ||
}); | ||
}); | ||
} | ||
} |