-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.acceptance.env.ts
More file actions
46 lines (40 loc) · 1.68 KB
/
Copy pathjest.acceptance.env.ts
File metadata and controls
46 lines (40 loc) · 1.68 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
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import util from 'node:util';
import { jest } from '@jest/globals';
import { keyrack } from 'rhachet/keyrack';
jest.setTimeout(90000); // we're calling downstream apis
// set console.log to not truncate nested objects
util.inspect.defaultOptions.depth = 5;
/**
* .what = verify that we're running from a valid project directory; otherwise, fail fast
* .why = prevent confusion and hard-to-debug errors from running tests in the wrong directory
*/
if (!existsSync(join(process.cwd(), 'package.json')))
throw new Error('no package.json found in cwd. are you @gitroot?');
/**
* .what = verify that the env has sufficient auth to run the tests if aws is used; otherwise, fail fast
* .why =
* - prevent time wasted waiting on tests to fail due to lack of credentials
* - prevent time wasted debugging tests which are failing due to hard-to-read missed credential errors
*/
const declapractUsePath = join(process.cwd(), 'declapract.use.yml');
const requiresAwsAuth =
existsSync(declapractUsePath) &&
readFileSync(declapractUsePath, 'utf8').includes('awsAccountId');
if (
requiresAwsAuth &&
!(process.env.AWS_PROFILE || process.env.AWS_ACCESS_KEY_ID)
)
throw new Error(
'no aws credentials present. please authenticate with aws to run acceptance tests',
);
/**
* .what = source credentials from keyrack for test env
* .why =
* - auto-inject keys into process.env
* - fail fast with helpful error if keyrack locked or keys absent
*/
const keyrackYmlPath = join(process.cwd(), '.agent/keyrack.yml');
if (existsSync(keyrackYmlPath))
keyrack.source({ env: 'test', owner: 'ehmpath', mode: 'strict' });