Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev-tool] Update to use vitest #28876

Merged
merged 4 commits into from
Mar 12, 2024
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
33 changes: 23 additions & 10 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 11 additions & 17 deletions common/tools/dev-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"unit-test": "npm run unit-test:node",
"unit-test:node": "mocha --require ts-node/register test/**/*.spec.ts test/*.spec.ts",
"unit-test:node": "vitest",
"unit-test:browser": "echo skipped",
"build:samples": "echo Skipped.",
"test": "echo Skipped."
Expand Down Expand Up @@ -60,35 +60,29 @@
"rollup": "^4.0.0",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-visualizer": "^5.9.3",
"semver": "^7.5.4",
"semver": "^7.6.0",
"strip-json-comments": "^5.0.1",
"ts-morph": "^22.0.0",
"ts-node": "^10.9.1",
"tslib": "^2.2.0",
"typescript": "~5.3.3",
"yaml": "^2.3.4",
"ts-morph": "^21.0.0"
"yaml": "^2.3.4"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.31.1",
"@microsoft/api-extractor": "^7.42.3",
"@types/archiver": "~6.0.2",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
"@types/decompress": "^4.2.4",
"@types/decompress": "^4.2.7",
"@types/fs-extra": "^11.0.4",
"@types/minimist": "^1.2.5",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/semver": "^7.5.6",
"autorest": "^3.5.1",
"@types/semver": "^7.5.8",
"@vitest/coverage-istanbul": "^1.3.1",
"autorest": "^3.7.1",
"builtin-modules": "^3.1.0",
"c8": "^8.0.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.54.0",
"karma": "^6.4.2",
"mkdirp": "^3.0.1",
"mocha": "^10.0.0",
"rimraf": "^5.0.5"
"rimraf": "^5.0.5",
"vitest": "^1.3.1"
}
}
1 change: 0 additions & 1 deletion common/tools/dev-tool/src/commands/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license

import chalk from "chalk";

import { baseCommands, baseCommandInfo } from ".";
import { resolveProject } from "../util/resolveProject";
import { createPrinter } from "../util/printer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import path from "node:path";
import readline from "node:readline";
import { spawnSync } from "node:child_process";

import { leafCommand, makeCommandInfo } from "../../framework/command";
import migrationTemplate, { MigrationTemplate } from "../../templates/migration";
import { createPrinter } from "../../util/printer";

import { ensureDir, pathExists, writeFile } from "fs-extra";

import { format } from "../../util/prettier";

const log = createPrinter("create-migration");
Expand Down
7 changes: 2 additions & 5 deletions common/tools/dev-tool/src/commands/admin/list/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// Licensed under the MIT license.

import { leafCommand, makeCommandInfo } from "../../../framework/command";

import path from "path";
import path from "node:path";
import { resolveRoot } from "../../../util/resolveProject";

import { readFile } from "fs/promises";

import { readFile } from "node:fs/promises";
import stripJsonComments from "strip-json-comments";

export const commandInfo = makeCommandInfo("packages", "list packages defined in the monorepo", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Licensed under the MIT license.

import { leafCommand, makeCommandInfo } from "../../../framework/command";
import path from "node:path";
import { resolveRoot } from "../../../util/resolveProject";
import { readdir } from "node:fs/promises";

export const commandInfo = makeCommandInfo("packages", "list service folders in the monorepo", {
relative: {
Expand All @@ -12,11 +15,6 @@ export const commandInfo = makeCommandInfo("packages", "list service folders in
},
});

import path from "path";
import { resolveRoot } from "../../../util/resolveProject";

import { readdir } from "fs/promises";

export async function getServiceFolders(root?: string): Promise<string[]> {
root ??= await resolveRoot();
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { readFile, writeFile } from "fs/promises";
import path from "path";
import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";

import { leafCommand, makeCommandInfo } from "../../framework/command";
import { getServiceFolders } from "./list/service-folders";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { createPrinter } from "../../util/printer";
import { run } from "../../util/run";
import { leafCommand } from "../../framework/command";
import { makeCommandInfo } from "../../framework/command";

import path from "node:path";
import fs from "node:fs/promises";
import os from "node:os";
Expand Down
4 changes: 1 addition & 3 deletions common/tools/dev-tool/src/commands/customization/apply.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license

import path from "path";

import path from "node:path";
import { resolveProject } from "../../util/resolveProject";
import { createPrinter } from "../../util/printer";
import { leafCommand } from "../../framework/command";
import { makeCommandInfo } from "../../framework/command";

import { customize } from "../../util/customization/customize";

const log = createPrinter("apply-customization");
Expand Down
2 changes: 1 addition & 1 deletion common/tools/dev-tool/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { METADATA_KEY, ProjectInfo, resolveProject, resolveRoot } from "../util/
import { createPrinter } from "../util/printer";
import { leafCommand } from "../framework/command";
import { makeCommandInfo } from "../framework/command";
import { cwd } from "process";
import { cwd } from "node:process";
import {
listAppliedMigrations,
getMigrationById,
Expand Down
3 changes: 1 addition & 2 deletions common/tools/dev-tool/src/commands/package/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license

import path from "path";

import path from "node:path";
import { resolveProject } from "../../util/resolveProject";
import { createPrinter } from "../../util/printer";
import { leafCommand } from "../../framework/command";
Expand Down
25 changes: 18 additions & 7 deletions common/tools/dev-tool/src/commands/run/build-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
// Licensed under the MIT license.

import path from "node:path";
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
import {
cpSync,
existsSync,
mkdirSync,
readFileSync,
readdirSync,
statSync,
writeFileSync,
} from "node:fs";
import { leafCommand, makeCommandInfo } from "../../framework/command";
import { createPrinter } from "../../util/printer";
import { resolveProject } from "../../util/resolveProject";
Expand Down Expand Up @@ -146,7 +154,7 @@ function copyOverrides(type: string, rootDir: string, filePath: string): void {
const fileToReplaceWith = path.join(
fileParsed.root,
fileParsed.dir,
`${fileParsed.name}-${type}.mts`
`${fileParsed.name}-${type}.mts`,
);
if (existsSync(fileToReplace) && existsSync(fileToReplaceWith)) {
log.info(`Copying over ${fileToReplaceWith} to ${fileToReplace}`);
Expand All @@ -156,20 +164,20 @@ function copyOverrides(type: string, rootDir: string, filePath: string): void {
rootDir,
relativeDir,
`${fileParsed.name}-${type}.d.mts`,
`${fileParsed.name}.d.ts`
`${fileParsed.name}.d.ts`,
);
overrideFile(
rootDir,
relativeDir,
`${fileParsed.name}-${type}.d.mts.map`,
`${fileParsed.name}.d.ts.map`
`${fileParsed.name}.d.ts.map`,
);
overrideFile(rootDir, relativeDir, `${fileParsed.name}-${type}.mjs`, `${fileParsed.name}.js`);
overrideFile(
rootDir,
relativeDir,
`${fileParsed.name}-${type}.mjs.map`,
`${fileParsed.name}.js.map`
`${fileParsed.name}.js.map`,
);
}
}
Expand All @@ -178,7 +186,7 @@ function overrideFile(
rootDir: string,
relativeDir: string,
sourceFile: string,
destinationFile: string
destinationFile: string,
): void {
const sourceFileType = path.join(process.cwd(), rootDir, relativeDir, sourceFile);
const destFileType = path.join(process.cwd(), rootDir, relativeDir, destinationFile);
Expand All @@ -189,7 +197,10 @@ function overrideFile(
class OverrideSet {
public map: Map<string, string>;

constructor(public type: "esm" | "commonjs", public name: string) {
constructor(
public type: "esm" | "commonjs",
public name: string,
) {
this.map = new Map();
}

Expand Down
5 changes: 1 addition & 4 deletions common/tools/dev-tool/src/commands/run/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import path from "path";

import path from "node:path";
import * as rollup from "rollup";
import nodeBuiltins from "builtin-modules";

import nodeResolve from "@rollup/plugin-node-resolve";
import cjs from "@rollup/plugin-commonjs";
import nodePolyfills from "rollup-plugin-polyfill-node";
import json from "@rollup/plugin-json";
import multiEntry from "@rollup/plugin-multi-entry";
import inject from "@rollup/plugin-inject";

import { leafCommand, makeCommandInfo } from "../../framework/command";
import { resolveProject, resolveRoot } from "../../util/resolveProject";
import { createPrinter } from "../../util/printer";
Expand Down
6 changes: 4 additions & 2 deletions common/tools/dev-tool/src/commands/run/check-api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { leafCommand, makeCommandInfo } from "../../framework/command";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { leafCommand, makeCommandInfo } from "../../framework/command";
import tsMin from "@_ts/min";
import tsMax from "@_ts/max";
import { createPrinter } from "../../util/printer";
import { resolveProject } from "../../util/resolveProject";
import path from "path";
import path from "node:path";
import semver from "semver";

export const commandInfo = makeCommandInfo(
Expand Down
8 changes: 5 additions & 3 deletions common/tools/dev-tool/src/commands/run/extract-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { leafCommand, makeCommandInfo } from "../../framework/command";
import {
Extractor,
Expand All @@ -8,13 +11,12 @@ import {
IConfigDtsRollup,
IConfigFile,
} from "@microsoft/api-extractor";

import { createPrinter } from "../../util/printer";
import { resolveProject } from "../../util/resolveProject";
import path from "path";
import { readFile } from "fs-extra";
import { readdir } from "fs/promises";
import { createReadStream, createWriteStream } from "fs";
import { readdir } from "node:fs/promises";
import { createReadStream, createWriteStream } from "node:fs";
import archiver from "archiver";

export const commandInfo = makeCommandInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license

import { leafCommand, makeCommandInfo } from "../../framework/command";

import concurrently from "concurrently";
import { createPrinter } from "../../util/printer";
import { isModuleProject } from "../../util/resolveProject";
Expand Down
1 change: 0 additions & 1 deletion common/tools/dev-tool/src/commands/run/testNodeTsxJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license

import { leafCommand, makeCommandInfo } from "../../framework/command";

import concurrently from "concurrently";
import { createPrinter } from "../../util/printer";
import { runTestsWithProxyTool } from "../../util/testUtils";
Expand Down
Loading
Loading