-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to configure process.env and function params for importOneExpor…
…tFromFile
- Loading branch information
Showing
14 changed files
with
130 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const actual = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
); | ||
const expected = 42; | ||
assert({ actual, expected }); | ||
} |
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
packages/dynamic-import-worker/tests/export_missing/export_missing.test.mjs
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,18 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// export missing | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./exporting_toto.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e.message; | ||
const expected = `No export named "answer" in ${new URL( | ||
"./exporting_toto.mjs", | ||
import.meta.url, | ||
)}`; | ||
assert({ actual, expected }); | ||
} |
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
packages/dynamic-import-worker/tests/file_missing/file_missing.test.mjs
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,17 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// file missing | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./toto.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e; | ||
const expected = new Error( | ||
`File not found at ${new URL("./toto.mjs", import.meta.url)}`, | ||
); | ||
assert({ actual, expected }); | ||
} |
52 changes: 0 additions & 52 deletions
52
packages/dynamic-import-worker/tests/import_one_export_from_file.test.mjs
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/dynamic-import-worker/tests/importing_function/exporting_getter.mjs
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,3 @@ | ||
export const get = (value) => { | ||
return value; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/dynamic-import-worker/tests/importing_function/importing_function.test.mjs
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,24 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const withoutParams = await importOneExportFromFile( | ||
`${new URL("./exporting_getter.mjs", import.meta.url)}#get`, | ||
); | ||
const withParam42 = await importOneExportFromFile( | ||
`${new URL("./exporting_getter.mjs", import.meta.url)}#get`, | ||
{ | ||
params: 42, | ||
}, | ||
); | ||
const actual = { | ||
withoutParams, | ||
withParam42, | ||
}; | ||
const expected = { | ||
withoutParams: undefined, | ||
withParam42: 42, | ||
}; | ||
assert({ actual, expected }); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/dynamic-import-worker/tests/importing_with_env/exporting_answer.mjs
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 @@ | ||
export const answer = process.env.TOTO ? 42 : 43; |
26 changes: 26 additions & 0 deletions
26
packages/dynamic-import-worker/tests/importing_with_env/importing_with_env.test.mjs
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,26 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const withoutEnv = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
); | ||
const withTotoEnv = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
{ | ||
env: { | ||
TOTO: "true", | ||
}, | ||
}, | ||
); | ||
const actual = { | ||
withoutEnv, | ||
withTotoEnv, | ||
}; | ||
const expected = { | ||
withoutEnv: 43, | ||
withTotoEnv: 42, | ||
}; | ||
assert({ actual, expected }); | ||
} |
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
packages/dynamic-import-worker/tests/runtime_error/runtime_error.test.mjs
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,23 @@ | ||
import { assert } from "@jsenv/assert"; | ||
|
||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// runtime error | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./runtime_error.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e.message; | ||
const expected = "here"; | ||
assert({ actual, expected }); | ||
} | ||
|
||
{ | ||
const actual = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
); | ||
const expected = 42; | ||
assert({ actual, expected }); | ||
} |