Skip to content

Commit

Permalink
feat(types): export CurrentsConfig for typed config files
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Dec 6, 2024
1 parent 93f574e commit aedfc04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
9 changes: 5 additions & 4 deletions packages/cypress-cloud/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// <reference types="cypress" />
import "source-map-support/register.js";
import 'source-map-support/register.js';

import { run as internalRun } from "./lib/run";
import { CurrentsRunAPI } from "./types";
export type { CurrentsRunAPI } from "./types";
import { run as internalRun } from './lib/run';
export type { CurrentsConfig } from './lib/config/config';
import { CurrentsRunAPI } from './types';
export type { CurrentsRunAPI } from './types';
/**
* Run Cypress tests with a cloud service of your choice and return the results
*
Expand Down
41 changes: 23 additions & 18 deletions packages/cypress-cloud/lib/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Debug from "debug";
import Debug from 'debug';

import { P, match } from "ts-pattern";
import { DetectedBrowser, ValidatedCurrentsParameters } from "../../types";
import { bootCypress } from "../bootstrap";
import { info, warn } from "../log";
import { getConfigFilePath } from "./path";
import { P, match } from 'ts-pattern';
import { DetectedBrowser, ValidatedCurrentsParameters } from '../../types';
import { bootCypress } from '../bootstrap';
import { info, warn } from '../log';
import { getConfigFilePath } from './path';

const debug = Debug("currents:config");
const debug = Debug('currents:config');

export type E2EConfig = {
batchSize: number;
Expand All @@ -18,6 +18,14 @@ export type ComponentConfig = {
type RetryConfig = {
hardFailureMaxRetries: number;
};

/**
* This is the type for `currents.config.*s`. If you are not officially using TypeScript,
* you can still type the exported config in your IDE by adding the following as a block comment
* above `module.exports` / `export default`:
*
* `@type {import('cypress-cloud').CurrentsConfig}`
*/
export type CurrentsConfig = {
projectId?: string;
recordKey?: string;
Expand All @@ -37,7 +45,7 @@ const defaultConfig: CurrentsConfig = {
component: {
batchSize: 5,
},
cloudServiceUrl: "https://cy.currents.dev",
cloudServiceUrl: 'https://cy.currents.dev',
networkHeaders: undefined,
};

Expand Down Expand Up @@ -68,10 +76,7 @@ export async function getCurrentsConfig(
}
}

warn(
"Failed to load config file, falling back to the default config. Attempted locations: %s",
configFilePath
);
warn('Failed to load config file, falling back to the default config. Attempted locations: %s', configFilePath);
_config = defaultConfig;
return _config;
}
Expand All @@ -81,14 +86,14 @@ async function loadConfigFile(filepath: string) {
debug("loading currents config file from '%s'", filepath);
return await import(filepath);
} catch (e) {
debug("failed loading config file from: %s", e);
debug('failed loading config file from: %s', e);
return null;
}
}

export type MergedConfig = Awaited<ReturnType<typeof getMergedConfig>>;
export async function getMergedConfig(params: ValidatedCurrentsParameters) {
debug("resolving cypress config");
debug('resolving cypress config');
const cypressResolvedConfig:
| (Cypress.ResolvedConfigOptions & {
projectRoot: string;
Expand All @@ -97,12 +102,12 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) {
})
| undefined = await bootCypress(params);

debug("cypress resolvedConfig: %O", cypressResolvedConfig);
debug('cypress resolvedConfig: %O', cypressResolvedConfig);

// @ts-ignore
const rawE2EPattern = cypressResolvedConfig.rawJson?.e2e?.specPattern;
let additionalIgnorePattern: string[] = [];
if (params.testingType === "component" && rawE2EPattern) {
if (params.testingType === 'component' && rawE2EPattern) {
// @ts-ignore
additionalIgnorePattern = rawE2EPattern;
}
Expand All @@ -112,14 +117,14 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) {
const result = {
projectRoot: cypressResolvedConfig?.projectRoot || process.cwd(),
projectId: params.projectId,
specPattern: cypressResolvedConfig?.specPattern || "**/*.*",
specPattern: cypressResolvedConfig?.specPattern || '**/*.*',
excludeSpecPattern:
// @ts-ignore
cypressResolvedConfig?.resolved.excludeSpecPattern.value ?? [],
additionalIgnorePattern,
resolved: cypressResolvedConfig,
experimentalCoverageRecording: params.experimentalCoverageRecording,
};
debug("merged config: %O", result);
debug('merged config: %O', result);
return result;
}

0 comments on commit aedfc04

Please sign in to comment.