Skip to content

Commit

Permalink
chore: update vitest script
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 23, 2024
1 parent 9bc1532 commit 90dd1c7
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions scripts/validation/vitest-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,35 @@ const paths = [
// path.join(__dirname, "..", "..", "packages", "middleware-user-agent"),
// path.join(__dirname, "..", "..", "packages", "middleware-websocket"),
// path.join(__dirname, "..", "..", "packages", "s3-presigned-post"),
// path.join(__dirname, "..", "..", "private", "aws-middleware-test"),
// path.join(__dirname, "..", "..", "private", "aws-util-test"),
// path.join(__dirname, "..", "..", "private", "aws-client-api-test"),
// path.join(__dirname, "..", "..", "private", "aws-client-retry-test"),
// path.join(__dirname, "..", "..", "private", "aws-echo-service"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-ec2"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-json"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-json-10"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-json-machinelearning"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-query"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson-apigateway"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson-glacier"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-restxml"),
// path.join(__dirname, "..", "..", "private", "aws-protocoltests-smithy-rpcv2-cbor"),
// path.join(__dirname, "..", "..", "private", "aws-restjson-server"),
// path.join(__dirname, "..", "..", "private", "aws-restjson-validation-server"),
path.join(__dirname, "..", "..", "private", "aws-middleware-test"),
path.join(__dirname, "..", "..", "private", "aws-util-test"),
path.join(__dirname, "..", "..", "private", "aws-client-api-test"),
path.join(__dirname, "..", "..", "private", "aws-client-retry-test"),
path.join(__dirname, "..", "..", "private", "aws-echo-service"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-ec2"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-json"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-json-10"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-json-machinelearning"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-query"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson-apigateway"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-restjson-glacier"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-restxml"),
path.join(__dirname, "..", "..", "private", "aws-protocoltests-smithy-rpcv2-cbor"),
path.join(__dirname, "..", "..", "private", "aws-restjson-server"),
path.join(__dirname, "..", "..", "private", "aws-restjson-validation-server"),
];

(async () => {
for (const folder of paths) {
const pkgJson = require(path.join(folder, "package.json"));

if (pkgJson.scripts.test) {
fs.rmSync(path.join(folder, "jest.config.js"));
if (pkgJson.scripts.test.includes("jest")) {
if (fs.existsSync(path.join(folder, "jest.config.js"))) {
fs.rmSync(path.join(folder, "jest.config.js"));
}

if (pkgJson.scripts.test.includes("jest") || pkgJson.scripts.test.includes("vitest")) {
console.log("setting unit test to vitest");

pkgJson.scripts.test = "vitest run";
Expand All @@ -97,19 +100,23 @@ const paths = [
`
);
} else if (pkgJson.scripts.test.includes("vitest")) {
pkgJson.scripts["test:watch"] ??= "vitest watch --passWithNot";
pkgJson.scripts["test:watch"] ??= "vitest watch --passWithNoTests";
}
}

for (const testType of ["integ", "e2e"]) {
const script = testType === "integ" ? "integration" : testType;
if (fs.existsSync(path.join(folder, `jest.config.${testType}.js`))) {
fs.rmSync(path.join(folder, `jest.config.${testType}.js`));
}
if (pkgJson.scripts[`test:${script}`]) {
pkgJson.scripts[`test:${script}:watch`] = `vitest watch -c vitest.config.${testType}.ts`;
if (pkgJson.scripts[`test:${script}`].includes("jest")) {
if (
pkgJson.scripts[`test:${script}`].includes("jest") ||
pkgJson.scripts[`test:${script}`].includes("vitest")
) {
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";
Expand Down

0 comments on commit 90dd1c7

Please sign in to comment.