forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-util] Migrate from mocha & karma to vitest (Azure#27551)
### Packages impacted by this PR `@azure/core-util` ### Describe the problem that is addressed by this PR An experiment to migrate away from mocha and karma to vitest. This eliminates the need for a browser bundle as vitest uses the test source files directly. I have also created a small plugin to avoid needing to add additional browser mappings for testing
- Loading branch information
Showing
24 changed files
with
1,293 additions
and
454 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,57 @@ | ||
{ | ||
"name": "@azure-tools/vite-plugin-browser-test-map", | ||
"version": "1.0.0", | ||
"description": "A vite plugin for dynamically remapping browser replacement maps for tests", | ||
"sdk-type": "utility", | ||
"type": "module", | ||
"private": true, | ||
"keywords": [ | ||
"vite-plugin" | ||
], | ||
"author": "Microsoft Corporation", | ||
"license": "MIT", | ||
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/common/tools/vite-plugin-browser-test-map/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Azure/azure-sdk-for-js.git", | ||
"directory": "common/tools/vite-plugin-browser-test-map" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Azure/azure-sdk-for-js/issues" | ||
}, | ||
"main": "dist/index.js", | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build": "tsc -p .", | ||
"build:samples": "echo Skipped.", | ||
"build:test": "tsc -p .", | ||
"clean": "rimraf dist/", | ||
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"./**/*.{ts,json,md}\"", | ||
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"./**/*.{ts,json,md}\"", | ||
"lint": "eslint src --ext .ts", | ||
"pack": "npm pack 2>&1", | ||
"prebuild": "npm run clean", | ||
"integration-test:browser": "echo skipped", | ||
"integration-test:node": "echo skipped", | ||
"integration-test": "npm run integration-test:node && npm run integration-test:browser", | ||
"unit-test:node": "echo skipped", | ||
"unit-test:browser": "echo skipped", | ||
"unit-test": "npm run unit-test:node && npm run unit-test:browser", | ||
"test": "npm run clean && npm run build:test && npm run unit-test" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"eslint": "^8.50.0", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.0", | ||
"typescript": "~5.2.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,32 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
function hasPackageCache<T extends {}>( | ||
obj: T | ||
): obj is T & { packageCache: Map<string, { data: any }> } { | ||
return "packageCache" in obj; | ||
} | ||
|
||
function rewriteDistPath(path: string): string { | ||
return path.replace(/^\.\/dist-esm\/(\S+)\.js$/, function replacer(_match, path) { | ||
return `./src/${path}`; | ||
}); | ||
} | ||
|
||
export default function browserTestMap() { | ||
return { | ||
name: "browser-test-config", | ||
enforce: "pre", | ||
configResolved: (config: {}) => { | ||
if (hasPackageCache(config)) { | ||
for (const { data } of config.packageCache.values()) { | ||
if (data.browser) { | ||
for (const [key, value] of Object.entries<string>(data.browser)) { | ||
data.browser[rewriteDistPath(key)] = rewriteDistPath(value); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
} |
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 @@ | ||
{ | ||
"extends": "../../../tsconfig", | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "Node16", | ||
"moduleResolution": "Node16", | ||
"outDir": "./dist", | ||
"declarationDir": "./types" | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
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,7 @@ | ||
{ | ||
"plugins": ["@azure/azure-sdk"], | ||
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], | ||
"rules": { | ||
"@azure/azure-sdk/ts-package-json-module": "off" | ||
} | ||
} |
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
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
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,14 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { delay, DelayOptions } from "./delay"; | ||
export { AbortOptions, cancelablePromiseRace, AbortablePromiseBuilder } from "./aborterUtils"; | ||
export { createAbortablePromise, CreateAbortablePromiseOptions } from "./createAbortablePromise"; | ||
export { delay, type DelayOptions } from "./delay"; | ||
export { | ||
type AbortOptions, | ||
cancelablePromiseRace, | ||
type AbortablePromiseBuilder, | ||
} from "./aborterUtils"; | ||
export { | ||
createAbortablePromise, | ||
type CreateAbortablePromiseOptions, | ||
} from "./createAbortablePromise"; | ||
export { getRandomIntegerInclusive } from "./random"; | ||
export { isObject, UnknownObject } from "./object"; | ||
export { isObject, type UnknownObject } from "./object"; | ||
export { isError, getErrorMessage } from "./error"; | ||
export { computeSha256Hash, computeSha256Hmac } from "./sha256"; | ||
export { isDefined, isObjectWithProperties, objectHasProperty } from "./typeGuards"; | ||
export { randomUUID } from "./uuidUtils"; | ||
export { isBrowser, isBun, isNode, isDeno, isReactNative, isWebWorker } from "./checkEnvironment"; | ||
export { uint8ArrayToString, stringToUint8Array, EncodingType } from "./bytesEncoding"; | ||
export { uint8ArrayToString, stringToUint8Array, type EncodingType } from "./bytesEncoding"; |
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
Oops, something went wrong.