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
3 changes: 0 additions & 3 deletions lib/package_json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { assertEquals } from "@std/assert";
import { getPackageJson, type GetPackageJsonOptions } from "./package_json.ts";

const versions = {
picocolors: "^1.0.0",
nodeTypes: "^20.9.0",
tsLib: "^2.6.2",
};
Expand Down Expand Up @@ -64,7 +63,6 @@ Deno.test("single entrypoint", () => {
},
devDependencies: {
"@types/node": versions.nodeTypes,
"picocolors": versions.picocolors,
"test-dep": "0.1.0",
"@deno/shim-deno": "~0.1.0",
},
Expand Down Expand Up @@ -519,7 +517,6 @@ Deno.test("peer dependencies", () => {
},
devDependencies: {
"@types/node": versions.nodeTypes,
"picocolors": versions.picocolors,
"test-dep": "0.1.0",
"@deno/shim-deno": "~0.1.0",
},
Expand Down
5 changes: 0 additions & 5 deletions lib/package_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ export function getPackageJson({
};
const testDevDependencies = testEnabled
? ({
...(!Object.keys(dependencies).includes("picocolors")
? {
"picocolors": "^1.0.0",
}
: {}),
// add dependencies from transform
...Object.fromEntries(
// ignore peer dependencies on this
Expand Down
36 changes: 18 additions & 18 deletions lib/test_runner/get_test_runner_code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Deno.test("gets code when no shim used", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -30,7 +30,7 @@ async function main() {
}

const scriptPath = "./script/" + filePath;
console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");
console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");
process.chdir(__dirname + "/script");
try {
require(scriptPath);
Expand All @@ -40,7 +40,7 @@ async function main() {
}

const esmPath = "./esm/" + filePath;
console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");
console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");
process.chdir(__dirname + "/esm");
await import(esmPath);
}
Expand All @@ -60,7 +60,7 @@ Deno.test("gets code when shim used", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");
const { pathToFileURL } = require("url");
const { testDefinitions } = require("test-shim-package/test-internals");
Expand All @@ -73,15 +73,15 @@ const filePaths = [
async function main() {
const testContext = {
process,
pc,
styleText,
};
for (const [i, filePath] of filePaths.entries()) {
if (i > 0) {
console.log("");
}

const scriptPath = "./script/" + filePath;
console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");
console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");
process.chdir(__dirname + "/script");
const scriptTestContext = {
origin: pathToFileURL(filePath).toString(),
Expand All @@ -96,7 +96,7 @@ async function main() {
await runTestDefinitions(testDefinitions.splice(0, testDefinitions.length), scriptTestContext);

const esmPath = "./esm/" + filePath;
console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");
console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");
process.chdir(__dirname + "/esm");
const esmTestContext = {
origin: pathToFileURL(filePath).toString(),
Expand Down Expand Up @@ -163,7 +163,7 @@ Deno.test("gets code when a preload module is used", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -187,7 +187,7 @@ async function main() {
}

const scriptPath = "./script/" + filePath;
console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");
console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");
process.chdir(__dirname + "/script");
try {
require(scriptPath);
Expand All @@ -197,7 +197,7 @@ async function main() {
}

const esmPath = "./esm/" + filePath;
console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");
console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");
process.chdir(__dirname + "/esm");
await import(esmPath);
}
Expand All @@ -218,7 +218,7 @@ Deno.test("gets code when a preload module is used without cjs", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -235,7 +235,7 @@ async function main() {
}

const esmPath = "./esm/" + filePath;
console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");
console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");
process.chdir(__dirname + "/esm");
await import(esmPath);
}
Expand All @@ -256,7 +256,7 @@ Deno.test("gets code when a preload module is used without esm", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -278,7 +278,7 @@ async function main() {
}

const scriptPath = "./script/" + filePath;
console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");
console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");
process.chdir(__dirname + "/script");
try {
require(scriptPath);
Expand Down Expand Up @@ -322,7 +322,7 @@ Deno.test("gets code when cjs is not used", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -336,7 +336,7 @@ async function main() {
}

const esmPath = "./esm/" + filePath;
console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");
console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");
process.chdir(__dirname + "/esm");
await import(esmPath);
}
Expand All @@ -356,7 +356,7 @@ Deno.test("gets code when esm is not used", () => {
});
assertEquals(
code,
`const pc = require("picocolors");
`const { styleText } = require("util");
const process = require("process");

const filePaths = [
Expand All @@ -370,7 +370,7 @@ async function main() {
}

const scriptPath = "./script/" + filePath;
console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");
console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");
process.chdir(__dirname + "/script");
try {
require(scriptPath);
Expand Down
8 changes: 4 additions & 4 deletions lib/test_runner/get_test_runner_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getTestRunnerCode(options: {
? undefined
: toJsFilePath(options.preloadEntryPoint);
const writer = createWriter();
writer.writeLine(`const pc = require("picocolors");`)
writer.writeLine(`const { styleText } = require("util");`)
.writeLine(`const process = require("process");`);
if (usesDenoTest) {
writer.writeLine(`const { pathToFileURL } = require("url");`);
Expand Down Expand Up @@ -61,7 +61,7 @@ export function getTestRunnerCode(options: {
if (usesDenoTest) {
writer.write("const testContext = ").inlineBlock(() => {
writer.writeLine("process,");
writer.writeLine("pc,");
writer.writeLine("styleText,");
}).write(";").newLine();
}
if (isolateTestFiles) {
Expand Down Expand Up @@ -131,7 +131,7 @@ export function getTestRunnerCode(options: {
if (options.includeScriptModule) {
writer.writeLine(`const scriptPath = "./script/" + filePath;`);
writer.writeLine(
`console.log("Running tests in " + pc.underline(scriptPath) + "...\\n");`,
`console.log("Running tests in " + styleText("underline", scriptPath) + "...\\n");`,
);
writer.writeLine(`process.chdir(__dirname + "/script");`);
if (usesDenoTest) {
Expand Down Expand Up @@ -159,7 +159,7 @@ export function getTestRunnerCode(options: {
}
writer.writeLine(`const esmPath = "./esm/" + filePath;`);
writer.writeLine(
`console.log("\\nRunning tests in " + pc.underline(esmPath) + "...\\n");`,
`console.log("\\nRunning tests in " + styleText("underline", esmPath) + "...\\n");`,
);
writer.writeLine(`process.chdir(__dirname + "/esm");`);
if (usesDenoTest) {
Expand Down
21 changes: 11 additions & 10 deletions lib/test_runner/test_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ function getContext() {
return output;
},
origin: "file:///file.ts",
pc: {
red(text: string) {
return `R${text}R`;
},
green(text: string) {
return `G${text}G`;
},
gray(text: string) {
return `Y${text}Y`;
},
styleText(format: string, text: string) {
switch (format) {
case "red":
return `R${text}R`;
case "green":
return `G${text}G`;
case "gray":
return `Y${text}Y`;
default:
return text;
}
},
process: {
stdout: {
Expand Down
19 changes: 8 additions & 11 deletions lib/test_runner/test_runner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// Copyright 2018-2024 the Deno authors. MIT license.

export interface Picocolors {
green(text: string): string;
red(text: string): string;
gray(text: string): string;
}

export interface NodeProcess {
stdout: {
write(text: string): void;
Expand All @@ -14,7 +8,8 @@ export interface NodeProcess {
}

export interface RunTestDefinitionsOptions {
pc: Picocolors;
/** `util.styleText` from Node.js. */
styleText(format: string, text: string): string;
process: NodeProcess;
/** The file the tests are running in. */
origin: string;
Expand Down Expand Up @@ -54,7 +49,9 @@ export async function runTestDefinitions(
for (const definition of testDefinitions) {
options.process.stdout.write("test " + definition.name + " ...");
if (definition.ignore) {
options.process.stdout.write(` ${options.pc.gray("ignored")}\n`);
options.process.stdout.write(
` ${options.styleText("gray", "ignored")}\n`,
);
continue;
}
const context = getTestContext(definition, undefined);
Expand Down Expand Up @@ -193,12 +190,12 @@ export async function runTestDefinitions(
function getStatusText(status: TestContext["status"]) {
switch (status) {
case "ok":
return options.pc.green(status);
return options.styleText("green", status);
case "fail":
case "pending":
return options.pc.red(status);
return options.styleText("red", status);
case "ignored":
return options.pc.gray(status);
return options.styleText("gray", status);
default: {
const _assertNever: never = status;
return status;
Expand Down
Loading