forked from aws/aws-sdk-js-v3
-
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.
test(core): install vitest (aws#6581)
* chore: install vitest * test: set vite to 4.x
- Loading branch information
Showing
25 changed files
with
310 additions
and
44 deletions.
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
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
2 changes: 2 additions & 0 deletions
2
packages/core/integ/request-handlers/request-handlers.integ.spec.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 was deleted.
Oops, something went wrong.
This file was deleted.
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
2 changes: 2 additions & 0 deletions
2
packages/core/src/submodules/account-id-endpoint/AccountIdEndpointModeConstants.spec.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
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
1 change: 1 addition & 0 deletions
1
packages/core/src/submodules/client/setCredentialFeature.spec.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
2 changes: 2 additions & 0 deletions
2
packages/core/src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.spec.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
2 changes: 2 additions & 0 deletions
2
packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4AConfig.spec.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
6 changes: 4 additions & 2 deletions
6
packages/core/src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.spec.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
12 changes: 7 additions & 5 deletions
12
packages/core/src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.spec.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
8 changes: 5 additions & 3 deletions
8
packages/core/src/submodules/httpAuthSchemes/utils/isClockSkewed.spec.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
2 changes: 2 additions & 0 deletions
2
packages/core/src/submodules/protocols/coercing-serializers.spec.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
2 changes: 2 additions & 0 deletions
2
packages/core/src/submodules/protocols/json/awsExpectUnion.spec.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
1 change: 1 addition & 0 deletions
1
packages/core/src/submodules/protocols/xml/parseXmlBody.spec.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,8 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ["**/*.integ.spec.{ts,js}"], | ||
environment: "node", | ||
}, | ||
}); |
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 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"], | ||
include: ["**/*.spec.{ts,js}"], | ||
environment: "node", | ||
}, | ||
}); |
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,102 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const walk = require("../utils/walk"); | ||
|
||
const paths = [path.join(__dirname, "..", "..", "packages", "core")]; | ||
|
||
(async () => { | ||
for (const folder of paths) { | ||
const pkgJson = require(path.join(folder, "package.json")); | ||
|
||
if (pkgJson.scripts.test) { | ||
if (pkgJson.scripts.test.includes("jest")) { | ||
console.log("setting unit test to vitest"); | ||
|
||
pkgJson.scripts.test = "vitest run"; | ||
fs.rmSync(path.join(folder, "jest.config.js")); | ||
fs.writeFileSync( | ||
path.join(folder, "vitest.config.ts"), | ||
`import { defineConfig } from "vitest/config"; | ||
export default defineConfig({ | ||
test: { | ||
exclude: ["**/*.{integ,e2e,browser}.spec.{ts,js}"], | ||
include: ["**/*.spec.{ts,js}"], | ||
environment: "node", | ||
}, | ||
}); | ||
` | ||
); | ||
} | ||
} | ||
|
||
for (const testType of ["integ", "e2e"]) { | ||
const script = testType === "integ" ? "integration" : testType; | ||
if (pkgJson.scripts[`test:${script}`]) { | ||
if (pkgJson.scripts[`test:${script}`].includes("jest")) { | ||
console.log(`setting ${testType} test to vitest`); | ||
|
||
pkgJson.scripts[`test:${script}`] = `vitest run -c vitest.config.${testType}.ts`; | ||
fs.rmSync(path.join(folder, `jest.config.${testType}.js`)); | ||
fs.writeFileSync( | ||
path.join(folder, `vitest.config.${testType}.ts`), | ||
`import { defineConfig } from "vitest/config"; | ||
export default defineConfig({ | ||
test: { | ||
include: ["**/*.${testType}.spec.{ts,js}"], | ||
environment: "node", | ||
}, | ||
}); | ||
` | ||
); | ||
} | ||
} | ||
} | ||
|
||
fs.writeFileSync(path.join(folder, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n"); | ||
|
||
for await (const file of walk(path.join(folder))) { | ||
if (file.endsWith(".spec.ts")) { | ||
let contents = fs.readFileSync(file, "utf-8"); | ||
|
||
const namespaces = { | ||
jest: "vi", | ||
}; | ||
|
||
const functionCalls = { | ||
beforeEach: "beforeEach", | ||
beforeAll: "beforeAll", | ||
afterEach: "afterEach", | ||
afterAll: "afterAll", | ||
describe: "describe", | ||
expect: "expect", | ||
}; | ||
|
||
const imports = ["test as it"]; | ||
|
||
contents = contents.replace(/\((\w+) as (jest|vi).Mock\)/g, "vi.mocked($1)"); | ||
|
||
for (const [old, _new] of Object.entries(namespaces)) { | ||
if (contents.includes(old + ".") || contents.includes(_new + ".")) { | ||
imports.push(_new); | ||
contents = contents.replace(new RegExp(old + "\\.", "g"), _new + "."); | ||
} | ||
} | ||
|
||
for (const [old, _new] of Object.entries(functionCalls)) { | ||
if (contents.includes(old + "(") || contents.includes(_new + "(")) { | ||
if (!_new.includes(".")) { | ||
imports.push(_new); | ||
} | ||
} | ||
} | ||
|
||
contents = contents.replace(/import {(.*?)} from "(vitest|vtestest)";/g, ""); | ||
contents = `import { ${imports.join(", ")} } from "vitest";\n\n` + contents; | ||
|
||
fs.writeFileSync(file, contents); | ||
} | ||
} | ||
} | ||
})(); |
Oops, something went wrong.