Skip to content

Commit aedfc04

Browse files
author
Evan Jacobs
committed
feat(types): export CurrentsConfig for typed config files
1 parent 93f574e commit aedfc04

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

packages/cypress-cloud/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/// <reference types="cypress" />
2-
import "source-map-support/register.js";
2+
import 'source-map-support/register.js';
33

4-
import { run as internalRun } from "./lib/run";
5-
import { CurrentsRunAPI } from "./types";
6-
export type { CurrentsRunAPI } from "./types";
4+
import { run as internalRun } from './lib/run';
5+
export type { CurrentsConfig } from './lib/config/config';
6+
import { CurrentsRunAPI } from './types';
7+
export type { CurrentsRunAPI } from './types';
78
/**
89
* Run Cypress tests with a cloud service of your choice and return the results
910
*

packages/cypress-cloud/lib/config/config.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Debug from "debug";
1+
import Debug from 'debug';
22

3-
import { P, match } from "ts-pattern";
4-
import { DetectedBrowser, ValidatedCurrentsParameters } from "../../types";
5-
import { bootCypress } from "../bootstrap";
6-
import { info, warn } from "../log";
7-
import { getConfigFilePath } from "./path";
3+
import { P, match } from 'ts-pattern';
4+
import { DetectedBrowser, ValidatedCurrentsParameters } from '../../types';
5+
import { bootCypress } from '../bootstrap';
6+
import { info, warn } from '../log';
7+
import { getConfigFilePath } from './path';
88

9-
const debug = Debug("currents:config");
9+
const debug = Debug('currents:config');
1010

1111
export type E2EConfig = {
1212
batchSize: number;
@@ -18,6 +18,14 @@ export type ComponentConfig = {
1818
type RetryConfig = {
1919
hardFailureMaxRetries: number;
2020
};
21+
22+
/**
23+
* This is the type for `currents.config.*s`. If you are not officially using TypeScript,
24+
* you can still type the exported config in your IDE by adding the following as a block comment
25+
* above `module.exports` / `export default`:
26+
*
27+
* `@type {import('cypress-cloud').CurrentsConfig}`
28+
*/
2129
export type CurrentsConfig = {
2230
projectId?: string;
2331
recordKey?: string;
@@ -37,7 +45,7 @@ const defaultConfig: CurrentsConfig = {
3745
component: {
3846
batchSize: 5,
3947
},
40-
cloudServiceUrl: "https://cy.currents.dev",
48+
cloudServiceUrl: 'https://cy.currents.dev',
4149
networkHeaders: undefined,
4250
};
4351

@@ -68,10 +76,7 @@ export async function getCurrentsConfig(
6876
}
6977
}
7078

71-
warn(
72-
"Failed to load config file, falling back to the default config. Attempted locations: %s",
73-
configFilePath
74-
);
79+
warn('Failed to load config file, falling back to the default config. Attempted locations: %s', configFilePath);
7580
_config = defaultConfig;
7681
return _config;
7782
}
@@ -81,14 +86,14 @@ async function loadConfigFile(filepath: string) {
8186
debug("loading currents config file from '%s'", filepath);
8287
return await import(filepath);
8388
} catch (e) {
84-
debug("failed loading config file from: %s", e);
89+
debug('failed loading config file from: %s', e);
8590
return null;
8691
}
8792
}
8893

8994
export type MergedConfig = Awaited<ReturnType<typeof getMergedConfig>>;
9095
export async function getMergedConfig(params: ValidatedCurrentsParameters) {
91-
debug("resolving cypress config");
96+
debug('resolving cypress config');
9297
const cypressResolvedConfig:
9398
| (Cypress.ResolvedConfigOptions & {
9499
projectRoot: string;
@@ -97,12 +102,12 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) {
97102
})
98103
| undefined = await bootCypress(params);
99104

100-
debug("cypress resolvedConfig: %O", cypressResolvedConfig);
105+
debug('cypress resolvedConfig: %O', cypressResolvedConfig);
101106

102107
// @ts-ignore
103108
const rawE2EPattern = cypressResolvedConfig.rawJson?.e2e?.specPattern;
104109
let additionalIgnorePattern: string[] = [];
105-
if (params.testingType === "component" && rawE2EPattern) {
110+
if (params.testingType === 'component' && rawE2EPattern) {
106111
// @ts-ignore
107112
additionalIgnorePattern = rawE2EPattern;
108113
}
@@ -112,14 +117,14 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) {
112117
const result = {
113118
projectRoot: cypressResolvedConfig?.projectRoot || process.cwd(),
114119
projectId: params.projectId,
115-
specPattern: cypressResolvedConfig?.specPattern || "**/*.*",
120+
specPattern: cypressResolvedConfig?.specPattern || '**/*.*',
116121
excludeSpecPattern:
117122
// @ts-ignore
118123
cypressResolvedConfig?.resolved.excludeSpecPattern.value ?? [],
119124
additionalIgnorePattern,
120125
resolved: cypressResolvedConfig,
121126
experimentalCoverageRecording: params.experimentalCoverageRecording,
122127
};
123-
debug("merged config: %O", result);
128+
debug('merged config: %O', result);
124129
return result;
125130
}

0 commit comments

Comments
 (0)