-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error when using top level await and outputting commonjs module
- Loading branch information
Showing
8 changed files
with
106 additions
and
18 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
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
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,10 +1,13 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { | ||
assertEquals, | ||
assertRejects, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { build, BuildOptions } from "../mod.ts"; | ||
|
||
Deno.test("should build", async () => { | ||
await runTest({ | ||
await runTest("test_project", { | ||
entryPoints: ["mod.ts"], | ||
outDir: "./npm", | ||
package: { | ||
|
@@ -55,7 +58,7 @@ test_runner.js | |
}); | ||
|
||
Deno.test("should build bin project", async () => { | ||
await runTest({ | ||
await runTest("test_project", { | ||
entryPoints: [{ | ||
kind: "bin", | ||
name: "add", | ||
|
@@ -98,30 +101,46 @@ Deno.test("should build bin project", async () => { | |
}); | ||
}); | ||
|
||
Deno.test("error for project with TLA and creating a CommonJS", async () => { | ||
await assertRejects(() => | ||
runTest("tla_project", { | ||
entryPoints: ["mod.ts"], | ||
outDir: "./npm", | ||
package: { | ||
name: "add", | ||
version: "1.0.0", | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
export interface Output { | ||
packageJson: any; | ||
npmIgnore: string; | ||
getFileText(filePath: string): string; | ||
} | ||
|
||
async function runTest( | ||
project: "test_project" | "tla_project", | ||
options: BuildOptions, | ||
checkOutput: (output: Output) => (Promise<void> | void), | ||
checkOutput?: (output: Output) => (Promise<void> | void), | ||
) { | ||
const originalCwd = Deno.cwd(); | ||
Deno.chdir("./tests/test_project"); | ||
Deno.chdir(`./tests/${project}`); | ||
try { | ||
await build(options); | ||
const getFileText = (filePath: string) => { | ||
return Deno.readTextFileSync(options.outDir + "/" + filePath); | ||
}; | ||
const packageJson = JSON.parse(getFileText("package.json")); | ||
const npmIgnore = getFileText(".npmignore"); | ||
await checkOutput({ | ||
packageJson, | ||
npmIgnore, | ||
getFileText, | ||
}); | ||
if (checkOutput) { | ||
const packageJson = JSON.parse(getFileText("package.json")); | ||
const npmIgnore = getFileText(".npmignore"); | ||
await checkOutput({ | ||
packageJson, | ||
npmIgnore, | ||
getFileText, | ||
}); | ||
} | ||
} finally { | ||
Deno.removeSync(options.outDir, { recursive: true }); | ||
Deno.chdir(originalCwd); | ||
|
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,9 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { add } from "./mod.ts"; | ||
|
||
Deno.test("should add in test project", () => { | ||
if (add(1, 2) !== 3) { | ||
throw new Error("FAIL"); | ||
} | ||
}); |
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,7 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
|
||
await new Promise<void>((resolve) => resolve()); | ||
|
||
export function add(a: number, b: number) { | ||
return a + b; | ||
} |
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