@empiricalrun/test-run 0.9.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @empiricalrun/test-run
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0ef2e11: feat(test-run): add environment variables fetching and injection
8
+
9
+ ### Patch Changes
10
+
11
+ - 226c361: fix: validate file existence in text edit tools, browser agent and run test tool and update fileName to filePath
12
+ - 8c7e9c6: fix: trim playwright_projects before environment update to ensure glob matching
13
+
3
14
  ## 0.9.4
4
15
 
5
16
  ### Patch Changes
package/dist/bin/index.js CHANGED
@@ -80,6 +80,16 @@ const repoDir = process.cwd();
80
80
  ]
81
81
  : undefined);
82
82
  const environmentSlug = process.env.TEST_RUN_ENVIRONMENT || "";
83
+ // Fetch environment variables from dashboard
84
+ const environmentVariables = await (0, dashboard_1.fetchEnvironmentVariables)();
85
+ const envOverrides = {};
86
+ // Convert environment variables to key-value pairs for process.env
87
+ environmentVariables.forEach((envVar) => {
88
+ envOverrides[envVar.name] = envVar.value;
89
+ });
90
+ if (Object.keys(envOverrides).length > 0) {
91
+ console.log(`Loaded environment variables: ${Object.keys(envOverrides).join(", ")}`);
92
+ }
83
93
  let environmentSpecificProjects = [];
84
94
  let platform = types_1.Platform.WEB;
85
95
  try {
@@ -109,6 +119,7 @@ const repoDir = process.cwd();
109
119
  projects: projectFilters,
110
120
  passthroughArgs: pwOptions.join(" "),
111
121
  platform,
122
+ envOverrides,
112
123
  repoDir,
113
124
  });
114
125
  }
@@ -117,6 +128,7 @@ const repoDir = process.cwd();
117
128
  projects: projectFilters,
118
129
  passthroughArgs: pwOptions.join(" "),
119
130
  platform,
131
+ envOverrides,
120
132
  });
121
133
  }
122
134
  const { hasTestPassed } = await (0, cmd_1.runTestsForCmd)(commandToRun, repoDir);
@@ -1,6 +1,15 @@
1
1
  import { Build, Environment } from "./types";
2
+ export type EnvironmentVariable = {
3
+ id: number;
4
+ project_id: number;
5
+ name: string;
6
+ value: string;
7
+ created_at: string;
8
+ updated_at: string;
9
+ };
2
10
  export declare const fetchEnvironmentAndBuild: (projectName: string, environmentSlug: string) => Promise<{
3
11
  environment: Environment;
4
12
  build: Build;
5
13
  }>;
14
+ export declare const fetchEnvironmentVariables: () => Promise<EnvironmentVariable[]>;
6
15
  //# sourceMappingURL=dashboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK7C,eAAO,MAAM,wBAAwB,GACnC,aAAa,MAAM,EACnB,iBAAiB,MAAM,KACtB,OAAO,CAAC;IACT,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,CAuDA,CAAC"}
1
+ {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../src/dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG7C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAIF,eAAO,MAAM,wBAAwB,GACnC,aAAa,MAAM,EACnB,iBAAiB,MAAM,KACtB,OAAO,CAAC;IACT,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,KAAK,CAAC;CACd,CAuDA,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAa,OAAO,CACxD,mBAAmB,EAAE,CA0CtB,CAAC"}
package/dist/dashboard.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchEnvironmentAndBuild = void 0;
6
+ exports.fetchEnvironmentVariables = exports.fetchEnvironmentAndBuild = void 0;
7
7
  const async_retry_1 = __importDefault(require("async-retry"));
8
8
  const utils_1 = require("./utils");
9
9
  const DOMAIN = process.env.DASHBOARD_DOMAIN || "https://dash.empirical.run";
@@ -42,3 +42,36 @@ const fetchEnvironmentAndBuild = async (projectName, environmentSlug) => {
42
42
  return data.data;
43
43
  };
44
44
  exports.fetchEnvironmentAndBuild = fetchEnvironmentAndBuild;
45
+ const fetchEnvironmentVariables = async () => {
46
+ if (!process.env.EMPIRICALRUN_API_KEY) {
47
+ return [];
48
+ }
49
+ try {
50
+ const data = await (0, async_retry_1.default)(async () => {
51
+ const envVarsResp = await fetch(`${DOMAIN}/api/environment-variables`, {
52
+ method: "GET",
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ Authorization: `Bearer ${process.env.EMPIRICALRUN_API_KEY}`,
56
+ },
57
+ });
58
+ if (!envVarsResp.ok) {
59
+ if (envVarsResp.status === 400) {
60
+ return { data: { environmentVariables: [] } };
61
+ }
62
+ throw new Error(`HTTP ${envVarsResp.status}: Failed to fetch environment variables`);
63
+ }
64
+ return (await envVarsResp.json());
65
+ }, {
66
+ retries: 3,
67
+ minTimeout: 1000,
68
+ maxTimeout: 60_000,
69
+ factor: 3,
70
+ });
71
+ return data && data.data ? data.data.environmentVariables : [];
72
+ }
73
+ catch (error) {
74
+ return [];
75
+ }
76
+ };
77
+ exports.fetchEnvironmentVariables = fetchEnvironmentVariables;
package/dist/index.d.ts CHANGED
@@ -2,10 +2,10 @@ import { spawnCmd } from "./lib/cmd";
2
2
  import { runSpecificTestsCmd } from "./lib/run-specific-test";
3
3
  import { TestCase } from "./types";
4
4
  export { runSpecificTestsCmd, spawnCmd };
5
- export declare function runSingleTest({ testName, suites, fileName, projects, envOverrides, repoDir, }: {
5
+ export declare function runSingleTest({ testName, suites, filePath, projects, envOverrides, repoDir, }: {
6
6
  testName: string;
7
7
  suites: string[];
8
- fileName: string;
8
+ filePath: string;
9
9
  projects: string[];
10
10
  envOverrides?: Record<string, string>;
11
11
  repoDir: string;
package/dist/index.js CHANGED
@@ -18,10 +18,10 @@ const utils_1 = require("./utils");
18
18
  // For test-run package, the library entrypoint, we only support web platform
19
19
  // The bin entrypoint has support for mobile also
20
20
  const supportedPlatform = types_1.Platform.WEB;
21
- async function runSingleTest({ testName, suites, fileName, projects, envOverrides, repoDir, }) {
21
+ async function runSingleTest({ testName, suites, filePath, projects, envOverrides, repoDir, }) {
22
22
  const testDir = "tests";
23
23
  const commandToRun = await (0, run_specific_test_1.runSpecificTestsCmd)({
24
- tests: [{ name: testName, dir: testDir, filePath: fileName, suites }],
24
+ tests: [{ name: testName, dir: testDir, filePath, suites }],
25
25
  projects,
26
26
  envOverrides,
27
27
  platform: supportedPlatform,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-run",
3
- "version": "0.9.4",
3
+ "version": "0.10.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"