Skip to content

Commit d4eb8b0

Browse files
authored
chore: run jest tests on compiled sources (#200)
1 parent d687760 commit d4eb8b0

File tree

14 files changed

+1145
-284
lines changed

14 files changed

+1145
-284
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
build
12
dist
23
node_modules
34
.DS_Store

babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

e2e/helpers/fixture.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import os from "node:os";
44
import path from "node:path";
55
import simpleGit, { SimpleGit } from "simple-git";
66

7-
export const FIXTURES_PATH = path.join(__dirname, "..", "fixtures");
7+
export const FIXTURES_PATH = path.join(
8+
__dirname,
9+
"..",
10+
"..",
11+
"..",
12+
"e2e",
13+
"fixtures"
14+
);
815
export const PREPARED_FIXTURES_PATH = fs.mkdtempSync(
916
os.tmpdir() + path.sep + "fixtures-"
1017
);

e2e/stubs/cloud-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CloudFunctions implements StubbedServer {
3030
],
3131
{
3232
stdio: "inherit",
33-
cwd: path.join(__dirname, "..", "..", "dist", "publish-to-bcr"),
33+
cwd: path.join(__dirname, "..", "..", "..", "dist", "publish-to-bcr"),
3434
env: {
3535
...process.env,
3636
INTEGRATION_TESTING: "1",

jest-snapshot-resolver.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import path from "path";
2+
3+
// Because jest snapshot tests run in the build directory, we need to map
4+
// the saved snapshot location back to the source tree.
5+
export function resolveSnapshotPath(testPath, snapshotExtension) {
6+
const pathInSourceTree = path.relative("build", testPath);
7+
const dirname = path.dirname(pathInSourceTree);
8+
return path.join(
9+
dirname,
10+
"__snapshots__",
11+
path.basename(pathInSourceTree).replace(".js", ".ts.snap")
12+
);
13+
}
14+
15+
export function resolveTestPath(snapshotFilePath, snapshotExtension) {
16+
return path
17+
.join("build", snapshotFilePath.replace("__snapshots__", ""))
18+
.replace(".ts.snap", ".js");
19+
}
20+
21+
export const testPathForConsistencyCheck = "e2e/e2e.spec.js";
22+
23+
export default {
24+
resolveSnapshotPath,
25+
resolveTestPath,
26+
testPathForConsistencyCheck,
27+
};

jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
export default {
7+
// Automatically clear mock calls, instances, contexts and results before every test
8+
clearMocks: true,
9+
10+
// The root directory that Jest should scan for tests and modules within.
11+
rootDir: "build",
12+
13+
// A list of paths to directories that Jest should use to search for files in.
14+
roots: ["src", "e2e"],
15+
16+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
17+
setupFilesAfterEnv: ["./jest.setup.js"],
18+
19+
// The path to a module that can resolve test<->snapshot path.
20+
snapshotResolver: "./jest-snapshot-resolver.js",
21+
22+
// A map from regular expressions to paths to transformers
23+
transform: {
24+
"\\.js$": "babel-jest",
25+
},
26+
};

jest.config.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"pnpm": "^8"
99
},
1010
"scripts": {
11-
"prebuild": "node tools/clean-dist-files.js",
12-
"build": "tsc && node tools/copy-dist-files.js",
11+
"prebuild": "node tools/clean.js",
12+
"build": "tsc && cp babel.config.json build/ && node tools/copy-dist-files.js",
1313
"//gcp-build": "Don't run any build steps on cloud run. See https://cloud.google.com/functions/docs/concepts/nodejs-runtime#npm_build_script/",
1414
"gcp-build": "",
15+
"pretest": "pnpm run build",
1516
"test": "jest src",
1617
"pree2e": "pnpm run build",
1718
"e2e": "jest e2e"
@@ -43,6 +44,7 @@
4344
"yaml": "^2.1.1"
4445
},
4546
"devDependencies": {
47+
"@babel/preset-env": "^7.26.0",
4648
"@jest/globals": "^29.7.0",
4749
"@octokit/webhooks-methods": "^4.0.0",
4850
"@types/archiver": "^6.0.2",
@@ -56,6 +58,7 @@
5658
"@types/tar": "^6.1.10",
5759
"@types/uuid": "^9.0.0",
5860
"archiver": "^6.0.1",
61+
"babel-jest": "^29.7.0",
5962
"expect": "^28.1.3",
6063
"globby": "^14.0.0",
6164
"imapflow": "^1.0.147",
@@ -65,8 +68,6 @@
6568
"mailparser": "3.6.6",
6669
"mockttp": "^3.10.0",
6770
"portfinder": "^1.0.32",
68-
"ts-jest": "^29.2.5",
69-
"ts-node": "^10.9.1",
7071
"typescript": "^5.0.0"
7172
},
7273
"pnpm": {

0 commit comments

Comments
 (0)