forked from denoland/std
-
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.
chore: run test in Node.js (denoland#5258)
Co-authored-by: Asher Gomez <[email protected]>
- Loading branch information
Showing
8 changed files
with
158 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
root = true | ||
|
||
[*.{ts,js,yml}] | ||
[*.{ts,js,yml,mjs}] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
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,2 @@ | ||
node_modules | ||
package-lock.json |
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,52 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { transform } from "sucrase"; | ||
import { readFile } from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import { pathToFileURL } from "node:url"; | ||
|
||
const decoder = new TextDecoder(); | ||
const encoder = new TextEncoder(); | ||
|
||
export async function resolve(specifier, context, nextResolve) { | ||
const match = specifier.match(/^@std\/([^\/]+)(\/[^\/]+)?$/); | ||
if (match) { | ||
const dir = match[1].replaceAll("-", "_"); | ||
const exportName = match[2] ? "." + match[2] : "."; | ||
const denoJson = await readFile(path.join(dir, "deno.json"), "utf-8"); | ||
const { exports } = JSON.parse(denoJson); | ||
const submodPath = path.resolve(dir, exports[exportName]); | ||
return nextResolve(pathToFileURL(submodPath).href, context); | ||
} | ||
|
||
return await nextResolve(specifier, context); | ||
} | ||
|
||
export async function load(specifier, context, nextLoad) { | ||
const { format, source } = await nextLoad(specifier, context).catch( | ||
async (error) => { | ||
if ( | ||
error.code === "ERR_UNKNOWN_FILE_EXTENSION" && | ||
specifier.endsWith(".ts") | ||
) { | ||
return await nextLoad(specifier, { | ||
...context, | ||
format: "module", | ||
}); | ||
} else { | ||
throw error; | ||
} | ||
}, | ||
); | ||
|
||
if (source && specifier.endsWith(".ts")) { | ||
return { | ||
format, | ||
source: encoder.encode( | ||
transform(decoder.decode(source), { transforms: ["typescript"] }).code, | ||
), | ||
}; | ||
} | ||
|
||
return { format, source }; | ||
} |
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,8 @@ | ||
{ | ||
"name": "node_test_runner", | ||
"private": true, | ||
"dependencies": { | ||
"@deno/shim-deno-test": "^0.5.0", | ||
"sucrase": "^3.35.0" | ||
} | ||
} |
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-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { Deno, testDefinitions } from "@deno/shim-deno-test"; | ||
import { register } from "node:module"; | ||
|
||
register(new URL("deno_compat_hooks.mjs", import.meta.url)); | ||
|
||
globalThis.Deno = Deno; | ||
globalThis.testDefinitions = testDefinitions; |
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,55 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { test } from "node:test"; | ||
|
||
import "../../collections/aggregate_groups_test.ts"; | ||
import "../../collections/associate_by_test.ts"; | ||
import "../../collections/associate_with_test.ts"; | ||
import "../../collections/chunk_test.ts"; | ||
import "../../collections/deep_merge_test.ts"; | ||
import "../../collections/distinct_by_test.ts"; | ||
import "../../collections/distinct_test.ts"; | ||
import "../../collections/drop_last_while_test.ts"; | ||
import "../../collections/drop_while_test.ts"; | ||
import "../../collections/filter_entries_test.ts"; | ||
import "../../collections/filter_keys_test.ts"; | ||
import "../../collections/filter_values_test.ts"; | ||
import "../../collections/find_single_test.ts"; | ||
import "../../collections/first_not_nullish_of_test.ts"; | ||
import "../../collections/includes_value_test.ts"; | ||
import "../../collections/intersect_test.ts"; | ||
import "../../collections/invert_by_test.ts"; | ||
// TODO(kt3k): Enable this | ||
// import "../../collections/invert_test.ts"; | ||
import "../../collections/join_to_string_test.ts"; | ||
import "../../collections/map_entries_test.ts"; | ||
import "../../collections/map_keys_test.ts"; | ||
import "../../collections/map_not_nullish_test.ts"; | ||
import "../../collections/map_values_test.ts"; | ||
import "../../collections/max_by_test.ts"; | ||
import "../../collections/max_of_test.ts"; | ||
import "../../collections/max_with_test.ts"; | ||
import "../../collections/min_by_test.ts"; | ||
import "../../collections/min_of_test.ts"; | ||
import "../../collections/min_with_test.ts"; | ||
import "../../collections/omit_test.ts"; | ||
import "../../collections/partition_entries_test.ts"; | ||
import "../../collections/partition_test.ts"; | ||
import "../../collections/permutations_test.ts"; | ||
import "../../collections/pick_test.ts"; | ||
import "../../collections/reduce_groups_test.ts"; | ||
import "../../collections/running_reduce_test.ts"; | ||
import "../../collections/sample_test.ts"; | ||
import "../../collections/sliding_windows.ts"; | ||
import "../../collections/sort_by_test.ts"; | ||
import "../../collections/sum_of_test.ts"; | ||
import "../../collections/take_last_while_test.ts"; | ||
import "../../collections/take_while_test.ts"; | ||
import "../../collections/union_test.ts"; | ||
import "../../collections/unzip_test.ts"; | ||
import "../../collections/without_all_test.ts"; | ||
import "../../collections/zip_test.ts"; | ||
|
||
for (const testDef of testDefinitions) { | ||
test(testDef.name, testDef.fn); | ||
} |
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