Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workspace-plugin): update react-library generator jest config to use swc #32122

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
// @ts-check
/* eslint-disable */

const { readFileSync } = require('node:fs');
const { join } = require('node:path');

// Reading the SWC compilation config and remove the "exclude"
// for the test files to be compiled by SWC
const { exclude: _, ...swcJestConfig } = JSON.parse(readFileSync(join(__dirname, '.swcrc'), 'utf-8'));

// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
if (swcJestConfig.swcrc === undefined) {
swcJestConfig.swcrc = false;
}

// Uncomment if using global setup/teardown files being transformed via swc
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
// jest needs EsModule Interop to find the default exported setup/teardown functions
// swcJestConfig.module.noInterop = false;

/**
* @type {import('@jest/types').Config.InitialOptions}
Expand All @@ -7,13 +26,7 @@ module.exports = {
displayName: '<%= projectName %>',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
isolatedModules: true,
},
],
'^.+\\.tsx?$': ['@swc/jest', swcJestConfig],
},
coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ describe('react-library generator', () => {
expect(readJson(tree, `${library.root}/.babelrc.json`)).toEqual(
expect.objectContaining({ extends: '../../../../.babelrc-v9.json' }),
);
expect(tree.read(`${library.root}/jest.config.js`, 'utf-8')).toEqual(
expect.stringContaining(`displayName: 'react-one-preview',`),
);

const jestConfig = tree.read(`${library.root}/jest.config.js`, 'utf-8');
expect(jestConfig).toEqual(expect.stringContaining(`displayName: 'react-one-preview',`));
expect(jestConfig).toEqual(expect.stringContaining(`'^.+\\\\.tsx?$': ['@swc/jest', swcJestConfig],`));
expect(tree.read(`${library.root}/README.md`, 'utf-8')).toEqual(
expect.stringContaining(stripIndents`
# @proj/react-one-preview
Expand Down
Loading