mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
fix: Validate all tests included in unit_tests.ts (#3879)
This commit is contained in:
parent
55ea854671
commit
a04e7270cd
3 changed files with 46 additions and 9 deletions
|
@ -9,22 +9,26 @@ import {
|
||||||
const readErrorStackPattern = new RegExp(
|
const readErrorStackPattern = new RegExp(
|
||||||
`^.*
|
`^.*
|
||||||
at unwrapResponse \\(.*dispatch_minimal\\.ts:.*\\)
|
at unwrapResponse \\(.*dispatch_minimal\\.ts:.*\\)
|
||||||
at Object.sendAsync \\(.*dispatch_minimal\\.ts:.*\\)
|
at Object.sendAsyncMinimal \\(.*dispatch_minimal\\.ts:.*\\)
|
||||||
at async Object\\.open \\(.*files\\.ts:.*\\).*$`,
|
at async Object\\.read \\(.*files\\.ts:.*\\).*$`,
|
||||||
"ms"
|
"ms"
|
||||||
);
|
);
|
||||||
|
|
||||||
test(async function sendAsyncStackTrace(): Promise<void> {
|
test(async function sendAsyncStackTrace(): Promise<void> {
|
||||||
const buf = new Uint8Array(10);
|
const buf = new Uint8Array(10);
|
||||||
await Deno.read(10, "nonexistent.txt", buf)
|
try {
|
||||||
.then(unreachable)
|
await Deno.read(10, buf);
|
||||||
.catch((error): void => {
|
unreachable();
|
||||||
|
} catch (error) {
|
||||||
assertMatch(error.stack, readErrorStackPattern);
|
assertMatch(error.stack, readErrorStackPattern);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
test(async function malformedMinimalControlBuffer(): Promise<void> {
|
test(async function malformedMinimalControlBuffer(): Promise<void> {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const res = Deno.core.send(1, new Uint8Array([1, 2, 3, 4, 5]));
|
const readOpId = Deno.core.ops()["read"];
|
||||||
|
// @ts-ignore
|
||||||
|
const res = Deno.core.send(readOpId, new Uint8Array([1, 2, 3, 4, 5]));
|
||||||
const header = res.slice(0, 12);
|
const header = res.slice(0, 12);
|
||||||
const buf32 = new Int32Array(
|
const buf32 = new Int32Array(
|
||||||
header.buffer,
|
header.buffer,
|
||||||
|
@ -33,7 +37,7 @@ test(async function malformedMinimalControlBuffer(): Promise<void> {
|
||||||
);
|
);
|
||||||
const arg = buf32[1];
|
const arg = buf32[1];
|
||||||
const result = buf32[2];
|
const result = buf32[2];
|
||||||
const message = new TextDecoder().decode(res.slice(12));
|
const message = new TextDecoder().decode(res.slice(12)).trim();
|
||||||
assert(arg < 0);
|
assert(arg < 0);
|
||||||
assertEquals(result, Deno.ErrorKind.InvalidInput);
|
assertEquals(result, Deno.ErrorKind.InvalidInput);
|
||||||
assertEquals(message, "Unparsable control buffer");
|
assertEquals(message, "Unparsable control buffer");
|
||||||
|
|
|
@ -296,3 +296,35 @@ testPerm({ read: true }, async function parsingUnitTestOutput(): Promise<void> {
|
||||||
assertEquals(result.actual, undefined);
|
assertEquals(result.actual, undefined);
|
||||||
assertEquals(result.expected, undefined);
|
assertEquals(result.expected, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure all unit test files (e.g. xxx_test.ts) are present as imports in
|
||||||
|
* cli/js/unit_tests.ts as it is easy to miss this out
|
||||||
|
*/
|
||||||
|
testPerm(
|
||||||
|
{ read: true },
|
||||||
|
async function assertAllUnitTestFilesImported(): Promise<void> {
|
||||||
|
const directoryTestFiles = Deno.readDirSync("./cli/js")
|
||||||
|
.map(k => k.name)
|
||||||
|
.filter(file => file.endsWith("_test.ts"));
|
||||||
|
const unitTestsFile: Uint8Array = Deno.readFileSync(
|
||||||
|
"./cli/js/unit_tests.ts"
|
||||||
|
);
|
||||||
|
const importLines = new TextDecoder("utf-8")
|
||||||
|
.decode(unitTestsFile)
|
||||||
|
.split("\n")
|
||||||
|
.filter(line => line.startsWith("import") && line.includes("_test.ts"));
|
||||||
|
const importedTestFiles = importLines.map(
|
||||||
|
relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)[1]
|
||||||
|
);
|
||||||
|
|
||||||
|
directoryTestFiles.forEach(dirFile => {
|
||||||
|
if (!importedTestFiles.includes(dirFile)) {
|
||||||
|
throw new Error(
|
||||||
|
"cil/js/unit_tests.ts is missing import of test file: cli/js/" +
|
||||||
|
dirFile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import "./console_test.ts";
|
||||||
import "./copy_file_test.ts";
|
import "./copy_file_test.ts";
|
||||||
import "./custom_event_test.ts";
|
import "./custom_event_test.ts";
|
||||||
import "./dir_test.ts";
|
import "./dir_test.ts";
|
||||||
|
import "./dispatch_minimal_test.ts";
|
||||||
import "./dispatch_json_test.ts";
|
import "./dispatch_json_test.ts";
|
||||||
import "./error_stack_test.ts";
|
import "./error_stack_test.ts";
|
||||||
import "./event_test.ts";
|
import "./event_test.ts";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue