migrate from Jest to Vitest

This commit is contained in:
Miron Costant 2024-03-27 14:18:22 -04:00
parent 2fa6325a3c
commit ad69d83e01
8 changed files with 2165 additions and 5151 deletions

View File

@ -1,15 +0,0 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverageFrom: ["src/**/*.ts"],
testPathIgnorePatterns: [
".*/dist/.*",
".*dist.*",
"/node_modules/(?!got)(.*)",
],
globals: {
"ts-jest": {
tsconfig: "tsconfig.json",
},
},
};

7128
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"package": "ncc build -o dist/setup src/setup-earthly.ts --source-map --license LICENSE && ncc build -o dist/cache-save src/cache-save.ts --source-map --license LICENSE", "package": "ncc build -o dist/setup src/setup-earthly.ts --source-map --license LICENSE && ncc build -o dist/cache-save src/cache-save.ts --source-map --license LICENSE",
"test": "jest --coverage src/**/*", "test": "vitest --coverage src/**/*",
"lint": "eslint src/**/*.ts" "lint": "eslint src/**/*.ts"
}, },
"type": "module", "type": "module",
@ -28,23 +28,21 @@
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@octokit/core": "^6.0.0", "@octokit/core": "^6.0.0",
"@octokit/plugin-paginate-rest": "^10.0.0", "@octokit/plugin-paginate-rest": "^10.0.0",
"jest-playback": "^4.0.0",
"make-dir": "^4.0.0", "make-dir": "^4.0.0",
"mkdirp-promise": "^5.0.1", "mkdirp-promise": "^5.0.1",
"node-fetch": "^3.2.10", "node-fetch": "^3.3.2",
"semver": "^7.3.8" "semver": "^7.6.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.2.0", "@types/node": "^20.11.30",
"@types/node": "^20.0.0", "@types/semver": "^7.5.8",
"@types/semver": "^7.3.13", "@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.4.0",
"@typescript-eslint/parser": "^7.0.0",
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.38.1",
"eslint": "^8.26.0", "@vitest/coverage-v8": "^1.4.0",
"jest": "^29.2.2", "eslint": "^8.57.0",
"prettier": "^3.0.0", "prettier": "^3.2.5",
"ts-jest": "^29.0.3", "typescript": "^5.4.3",
"typescript": "^5.0.0" "vitest": "^1.4.0"
} }
} }

View File

@ -1,40 +1,43 @@
import {getVersionObject} from "../get-version"; import { getVersionObject } from "../get-version";
import * as semver from 'semver'; import * as semver from "semver";
// The latest version since this test was last changed // The latest version since this test was last changed
// Feel free to update it if earthly has been updated // Feel free to update it if earthly has been updated
const latest = '0.6.23'; const latest = "0.6.23";
describe("get-version", () => { describe("get-version", () => {
describe('latest range versions', () => { describe("latest range versions", () => {
it.each(["latest", "*", "^0", "0.*.*", "0.6.*"] as const)("should match %s versions", async (ver) => { it.each(["latest", "*", "^0", "0.*.*", "0.6.*"] as const)(
const v = await getVersionObject(ver, false); "should match %s versions",
expect(semver.gte(v.tag_name, latest)); async (ver) => {
}); const v = await getVersionObject(ver, false);
expect(semver.gte(v.tag_name, latest));
}
);
});
describe("range versions", () => {
it.each([
{ spec: "0.4.*", gte: "0.4.0", lt: "0.5.0" },
{ spec: "v0.4.*", gte: "0.4.0", lt: "0.5.0" },
{ spec: "0.6.1", eq: "0.6.1" },
{ spec: "v0.6.0", eq: "0.6.0" },
] as const)("should match %s versions", async (test) => {
console.log(JSON.stringify(test));
const v = await getVersionObject(test.spec, false);
if (test.gte) expect(semver.gte(v.tag_name, test.gte));
if (test.lt) expect(semver.lt(v.tag_name, test.lt));
if (test.eq) expect(semver.eq(v.tag_name, test.eq));
}); });
describe("range versions", () => { });
it.each([ describe("valid semver", () => {
{spec: "0.4.*", gte: "0.4.0", lt: "0.5.0"}, it.each([
{spec: "v0.4.*", gte: "0.4.0", lt: "0.5.0"}, { spec: "0.4.*", valid: false },
{spec: "0.6.1", eq: '0.6.1'}, { spec: "v0.4.1", valid: false },
{spec: "v0.6.0", eq: "0.6.0"}, { spec: "0.6.1", valid: true },
] as const)("should match %s versions", async (test) => { ] as const)("%s is valid semantic version", async (test) => {
console.log(JSON.stringify(test)); console.log(JSON.stringify(test));
const v = await getVersionObject(test.spec, false); const v = semver.valid(test.spec) != null;
if (test.gte) expect(semver.gte(v.tag_name, test.gte)); expect(v == test.valid);
if (test.lt) expect(semver.lt(v.tag_name, test.lt));
if (test.eq) expect(semver.eq(v.tag_name, test.eq));
});
});
describe("valid semver", () => {
it.each([
{spec: "0.4.*", valid: false},
{spec: "v0.4.1", valid: false},
{spec: "0.6.1", valid: true},
] as const)("%s is valid semantic version", async (test) => {
console.log(JSON.stringify(test));
const v = semver.valid(test.spec) != null;
expect(v == test.valid);
});
}); });
});
}); });

View File

@ -1,64 +1,15 @@
{ {
"compilerOptions": { "compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext", "target": "ESNext",
"module": "ESNext", "module": "ESNext",
"moduleResolution": "node", "moduleResolution": "node",
// "allowJs": true, /* Allow javascript files to be compiled. */ "types": ["vitest/globals"],
// "checkJs": true, /* Report errors in .js files. */ "outDir": "./lib",
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ "rootDir": "./src",
// "declaration": true, /* Generates corresponding '.d.ts' file. */ "strict": true,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ "noImplicitAny": false,
// "sourceMap": true, /* Generates corresponding '.map' file. */ "esModuleInterop": true
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}, },
"exclude": ["node_modules", "**/*.test.ts"] "include": ["src/**/*"],
"exclude": ["node_modules"]
} }

7
vite.config.ts Normal file
View File

@ -0,0 +1,7 @@
import { defineConfig } from "vite";
import vitestConfig from "./vitest.config";
export default defineConfig({
plugins: [],
test: vitestConfig.test,
});

8
vitest.config.ts Normal file
View File

@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globals: true,
environment: "node",
},
});