Skip to content

Commit

Permalink
chore: run jest tests on compiled sources (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide authored Jan 10, 2025
1 parent d687760 commit d4eb8b0
Show file tree
Hide file tree
Showing 14 changed files with 1,145 additions and 284 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
dist
node_modules
.DS_Store
Expand Down
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
9 changes: 8 additions & 1 deletion e2e/helpers/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import os from "node:os";
import path from "node:path";
import simpleGit, { SimpleGit } from "simple-git";

export const FIXTURES_PATH = path.join(__dirname, "..", "fixtures");
export const FIXTURES_PATH = path.join(
__dirname,
"..",
"..",
"..",
"e2e",
"fixtures"
);
export const PREPARED_FIXTURES_PATH = fs.mkdtempSync(
os.tmpdir() + path.sep + "fixtures-"
);
Expand Down
2 changes: 1 addition & 1 deletion e2e/stubs/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CloudFunctions implements StubbedServer {
],
{
stdio: "inherit",
cwd: path.join(__dirname, "..", "..", "dist", "publish-to-bcr"),
cwd: path.join(__dirname, "..", "..", "..", "dist", "publish-to-bcr"),
env: {
...process.env,
INTEGRATION_TESTING: "1",
Expand Down
27 changes: 27 additions & 0 deletions jest-snapshot-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import path from "path";

// Because jest snapshot tests run in the build directory, we need to map
// the saved snapshot location back to the source tree.
export function resolveSnapshotPath(testPath, snapshotExtension) {
const pathInSourceTree = path.relative("build", testPath);
const dirname = path.dirname(pathInSourceTree);
return path.join(
dirname,
"__snapshots__",
path.basename(pathInSourceTree).replace(".js", ".ts.snap")
);
}

export function resolveTestPath(snapshotFilePath, snapshotExtension) {
return path
.join("build", snapshotFilePath.replace("__snapshots__", ""))
.replace(".ts.snap", ".js");
}

export const testPathForConsistencyCheck = "e2e/e2e.spec.js";

export default {
resolveSnapshotPath,
resolveTestPath,
testPathForConsistencyCheck,
};
26 changes: 26 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

export default {
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// The root directory that Jest should scan for tests and modules within.
rootDir: "build",

// A list of paths to directories that Jest should use to search for files in.
roots: ["src", "e2e"],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ["./jest.setup.js"],

// The path to a module that can resolve test<->snapshot path.
snapshotResolver: "./jest-snapshot-resolver.js",

// A map from regular expressions to paths to transformers
transform: {
"\\.js$": "babel-jest",
},
};
28 changes: 0 additions & 28 deletions jest.config.ts

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"pnpm": "^8"
},
"scripts": {
"prebuild": "node tools/clean-dist-files.js",
"build": "tsc && node tools/copy-dist-files.js",
"prebuild": "node tools/clean.js",
"build": "tsc && cp babel.config.json build/ && node tools/copy-dist-files.js",
"//gcp-build": "Don't run any build steps on cloud run. See https://cloud.google.com/functions/docs/concepts/nodejs-runtime#npm_build_script/",
"gcp-build": "",
"pretest": "pnpm run build",
"test": "jest src",
"pree2e": "pnpm run build",
"e2e": "jest e2e"
Expand Down Expand Up @@ -43,6 +44,7 @@
"yaml": "^2.1.1"
},
"devDependencies": {
"@babel/preset-env": "^7.26.0",
"@jest/globals": "^29.7.0",
"@octokit/webhooks-methods": "^4.0.0",
"@types/archiver": "^6.0.2",
Expand All @@ -56,6 +58,7 @@
"@types/tar": "^6.1.10",
"@types/uuid": "^9.0.0",
"archiver": "^6.0.1",
"babel-jest": "^29.7.0",
"expect": "^28.1.3",
"globby": "^14.0.0",
"imapflow": "^1.0.147",
Expand All @@ -65,8 +68,6 @@
"mailparser": "3.6.6",
"mockttp": "^3.10.0",
"portfinder": "^1.0.32",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1",
"typescript": "^5.0.0"
},
"pnpm": {
Expand Down
Loading

0 comments on commit d4eb8b0

Please sign in to comment.