Skip to content

Commit

Permalink
Merge branch 'main' into caniuse
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSonOfThomp authored Feb 12, 2024
2 parents c6e5be7 + ee6ad39 commit 09fdbef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-ravens-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lg-tools/test': patch
---

Updates default jest config path to reference the correct file (in `node_modules`)
5 changes: 3 additions & 2 deletions tools/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"@emotion/css": "11.9.0",
"@emotion/react": "11.11.1",
"@emotion/server": "11.11.0",
"@leafygreen-ui/testing-lib": "^0.4.1",
"@lg-tools/build": "0.3.2",
"@lg-tools/meta": "0.3.0",
"@leafygreen-ui/testing-lib": "^0.4.1",
"@testing-library/dom": "9.3.1",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/react": "14.0.0",
Expand All @@ -30,6 +30,7 @@
"@types/jest": "29.5.3",
"@types/jest-axe": "3.5.5",
"babel-jest": "29.6.2",
"chalk": "4.1.2",
"cross-spawn": "7.0.3",
"fs-extra": "11.1.1",
"jest": "29.6.2",
Expand All @@ -40,4 +41,4 @@
"react-test-renderer": "18.2.0",
"regenerator-runtime": "0.14.0"
}
}
}
16 changes: 8 additions & 8 deletions tools/test/src/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import { test as lgTest } from '.';

const spawnSpy = jest.spyOn(child_process, 'spawn');

const defaultConfigPath = path.resolve(
process.cwd(),
'node_modules/@lg-tools/test/config/jest.config.js',
);

describe('tools/test', () => {
const baseArgs = [
'--config',
path.resolve(__dirname, '../config/jest.config.js'),
'--rootDir',
process.cwd(),
];
const baseArgs = ['--config', defaultConfigPath, '--rootDir', process.cwd()];

const baseEnv = { env: expect.objectContaining({ JEST_ENV: 'client' }) };

beforeEach(() => {
spawnSpy.mockImplementation(
(...args) =>
(..._args) =>
({
on: (e: string, cb: (...args: Array<any>) => void) => {},
on: (_e: string, _cb: (..._args: Array<any>) => void) => {},
} as ChildProcess),
);
});
Expand Down
13 changes: 9 additions & 4 deletions tools/test/src/utils/getConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
import { exitWithErrorMessage } from '@lg-tools/meta';
import chalk from 'chalk';
import fse from 'fs-extra';
import path from 'path';

Expand All @@ -17,17 +18,17 @@ export function getConfigFile(options: TestCommandOptions): string {
const localConfigFile = path.resolve(rootDir, 'jest.config.js');
const defaultConfigFile = path.resolve(
rootDir,
'tools/test/config/jest.config.js',
'node_modules/@lg-tools/test/config/jest.config.js',
);
const react17ConfigFile = path.resolve(
rootDir,
'tools/test/config/react17/jest.config.js',
'node_modules/@lg-tools/test/config/react17/jest.config.js',
);

if (react17) {
if (fse.existsSync(react17ConfigFile)) {
console.log('Using React 17 test config');
verbose && console.log(react17ConfigFile);
console.log(chalk.bold('Using React 17 test config'));
verbose && console.log(`\t${react17ConfigFile}`);
return react17ConfigFile; // If react17 flag was used, use that config
} else {
exitWithErrorMessage(
Expand All @@ -37,8 +38,12 @@ export function getConfigFile(options: TestCommandOptions): string {
}

if (fse.existsSync(localConfigFile)) {
verbose && console.log(chalk.gray.bold('Using local config file'));
verbose && console.log(chalk.gray(`\t${localConfigFile}`));
return localConfigFile; // otherwise look for a config at the root
}

verbose && console.log(chalk.gray.bold('Using default config file'));
verbose && console.log(chalk.gray(`\t${defaultConfigFile}`));
return defaultConfigFile; // fallback to the default config
}
5 changes: 3 additions & 2 deletions tools/test/src/utils/getJestBinary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
import { exitWithErrorMessage } from '@lg-tools/meta';
import chalk from 'chalk';
import fse from 'fs-extra';
import path from 'path';

Expand All @@ -24,8 +25,8 @@ export function getJestBinary(options: TestCommandOptions): string {

const jestVersion = getCurrentJestVersion(jestBinaryPath);

verbose && console.log(`Using jest@${jestVersion}`);
verbose && console.log('Jest binary path:', jestBinaryPath);
verbose && console.log(chalk.gray.bold(`\nUsing jest@${jestVersion}`));
verbose && console.log(chalk.gray('\tJest binary path:', jestBinaryPath));

return jestBinaryPath;
}

0 comments on commit 09fdbef

Please sign in to comment.