Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/docs/e2e/Playground.cy.res
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ describe("Playground", () => {
)
})

it("should run exception code with v13.0.0-alpha.6", () => {
let code = `exception HttpError({status: int})

let isRetriable: exn => bool = error =>
switch error {
| HttpError({status: 502 | 503 | 504}) => true
| _ => false
}

Console.log(isRetriable(HttpError({status: 500})))`
let compressedCode = LzString.lzString.compressToEncodedURIComponent(code)
visit(`/try?version=v13.0.0-alpha.6&code=${compressedCode}`)
waitForPlayground()

get("pre.whitespace-pre-wrap")->shouldContainText("Primitive_exceptions.mjs")->ignore
getByTestId("control-panel")
->find("button")
->containsChainable("Run")
->click
->ignore

get("div.whitespace-pre-wrap pre")->shouldContainText("false")->ignore
})

it("should open the landing page example in the playground with code and compiled output", () => {
containsSelector("a", "Edit this example in Playground")
->scrollIntoView
Expand Down
26 changes: 26 additions & 0 deletions apps/guide/__tests__/GuideRuntime_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ test("normalizes old compiler runtime import filenames", async () => {
)->toBe("core__array")
})

test("resolves v13 exception imports to the published runtime file", async () => {
let compilerVersion = Semver.parse("v13.0.0-alpha.6")->Option.getOrThrow
let url = GuideRuntimeImport.url(
~bundleBaseUrl="https://cdn.rescript-lang.org",
~compilerVersion,
"./stdlib/Primitive_exceptions.mjs",
)

expect(url)->toBe(
"https://cdn.rescript-lang.org/v13.0.0-alpha.6/compiler-builtins/stdlib/Primitive_exceptions.js",
)
})

test("preserves runtime imports that already use the published extension", async () => {
let compilerVersion = Semver.parse("v12.3.1")->Option.getOrThrow
let url = GuideRuntimeImport.url(
~bundleBaseUrl="https://cdn.rescript-lang.org",
~compilerVersion,
"./stdlib/Stdlib_Array.js",
)

expect(url)->toBe(
"https://cdn.rescript-lang.org/v12.3.1/compiler-builtins/stdlib/Stdlib_Array.js",
)
})

test("normalizes old compiler versions for runtime imports", async () => {
let alpha7 = Semver.parse("v12.0.0-alpha.7")->Option.getOrThrow
let alpha9 = Semver.parse("v12.0.0-alpha.9")->Option.getOrThrow
Expand Down
9 changes: 8 additions & 1 deletion packages/playground/src/CompilerManagerHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ module CdnMeta = {
let getLibraryCmijUrl = (baseUrl, version, libraryName: string): string =>
`${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js`

let getStdlibRuntimeUrl = (baseUrl, version, filename) =>
let getStdlibRuntimeUrl = (baseUrl, version, filename) => {
// The compiler emits .mjs imports, while the published runtime bundles use .js.
let filename = if filename->String.endsWith(".mjs") {
filename->String.slice(~start=0, ~end=-4) ++ ".js"
} else {
filename
}
`${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}`
}
}

module FinalResult = {
Expand Down
Loading