Repository navigation
Expand file tree
/
Copy pathjest.e2e.setup.ts
More file actions
48 lines (43 loc) · 1.61 KB
/
Copy pathjest.e2e.setup.ts
File metadata and controls
48 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Jest globalSetup for E2E tests.
*
* Creates a `node_modules/serverless-appsync-plugin` symlink under
* `examples/` so that every example project resolves the plugin from
* the current source tree (via Node's module resolution walking up
* the directory tree), without needing a per-example `npm install`.
*
* This is invoked once before any e2e test runs.
*/
import * as fs from 'fs';
import * as path from 'path';
export default async function globalSetup(): Promise<void> {
const repoRoot = path.resolve(__dirname);
const examplesNodeModules = path.join(repoRoot, 'examples', 'node_modules');
const pluginSymlinkPath = path.join(
examplesNodeModules,
'serverless-appsync-plugin',
);
fs.mkdirSync(examplesNodeModules, { recursive: true });
// Remove any pre-existing entry (whether file, symlink, or directory)
// so we always get a fresh symlink pointing at the current repo root.
if (
fs.existsSync(pluginSymlinkPath) ||
fs.lstatSync(pluginSymlinkPath, { throwIfNoEntry: false })
) {
try {
fs.rmSync(pluginSymlinkPath, { recursive: true, force: true });
} catch {
// ignore
}
}
// Use a relative symlink so it works in any clone location.
fs.symlinkSync('../..', pluginSymlinkPath, 'dir');
// Make sure `lib/` is built — synthesis needs the compiled plugin.
const libPath = path.join(repoRoot, 'lib', 'index.js');
if (!fs.existsSync(libPath)) {
throw new Error(
`Plugin build artifact not found at ${libPath}. ` +
`Run \`npm run build\` before \`npm run test:e2e\`, or use \`npm run test:e2e\` directly which builds first.`,
);
}
}