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(nextjs): can set compiler when setting up nxComponentTestingPreset #19171

Merged
merged 21 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c1a0442
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Sep 12, 2023
e3afced
Merge branch 'master' into next-component-testing-compiler
erenken Sep 14, 2023
64a9fb4
Merge branch 'master' into next-component-testing-compiler
erenken Sep 15, 2023
3ef461f
Merge branch 'master' into next-component-testing-compiler
erenken Sep 26, 2023
5864c7b
Merge branch 'master' into next-component-testing-compiler
erenken Sep 28, 2023
66b2a78
Merge branch 'nrwl:master' into next-component-testing-compiler
erenken Oct 7, 2023
38e388e
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Oct 10, 2023
d8d4087
Merge branch 'master' into next-component-testing-compiler
erenken Oct 10, 2023
635ab41
Merge branch 'master' into next-component-testing-compiler
erenken Oct 29, 2023
428b00a
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Oct 29, 2023
b01efa1
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Oct 29, 2023
e023b19
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Oct 29, 2023
53e69b3
Merge branch 'master' into next-component-testing-compiler
erenken Oct 31, 2023
adf5ae0
Merge branch 'master' into next-component-testing-compiler
erenken Nov 1, 2023
17b3e01
Merge branch 'master' into next-component-testing-compiler
erenken Nov 2, 2023
7da3996
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Nov 2, 2023
f27887a
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Nov 2, 2023
4cb9f37
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Nov 2, 2023
4c8c817
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Nov 2, 2023
f1f56dc
feat(nextjs): can set compiler when setting up `nxComponentTestingPre…
erenken Nov 2, 2023
643fa2a
Merge branch 'master' into next-component-testing-compiler
erenken Nov 3, 2023
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
43 changes: 43 additions & 0 deletions e2e/next-extensions/src/next-component-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
cleanupProject,
createFile,
newProject,
runCLI,
Expand All @@ -14,6 +15,8 @@ describe('NextJs Component Testing', () => {
});
});

afterAll(() => cleanupProject());

it('should test a NextJs app', () => {
const appName = uniq('next-app');
createAppWithCt(appName);
Expand All @@ -30,6 +33,30 @@ describe('NextJs Component Testing', () => {
}
});

it('should test a NextJs app using babel compiler', () => {
const appName = uniq('next-app');
createAppWithCt(appName);
// add bable compiler to app
addBabelSupport(`apps/${appName}`);
if (runE2ETests()) {
expect(runCLI(`component-test ${appName} --no-watch`)).toContain(
'All specs passed!'
);
}
});

it('should test a NextJs lib using babel compiler', async () => {
const libName = uniq('next-lib');
createLibWithCt(libName, false);
// add bable compiler to lib
addBabelSupport(`libs/${libName}`);
if (runE2ETests()) {
expect(runCLI(`component-test ${libName} --no-watch`)).toContain(
'All specs passed!'
);
}
});

it('should test a NextJs lib', async () => {
const libName = uniq('next-lib');
createLibWithCt(libName, false);
Expand Down Expand Up @@ -64,6 +91,22 @@ describe('NextJs Component Testing', () => {
});
});

function addBabelSupport(path: string) {
updateFile(`${path}/cypress.config.ts`, (content) => {
// apply babel compiler
return content.replace(
'nxComponentTestingPreset(__filename)',
'nxComponentTestingPreset(__filename, {compiler: "babel"})'
);
});

// added needed .babelrc file with defaults
createFile(
`${path}/.babelrc`,
JSON.stringify({ presets: ['next/babel'], plugins: ['istanbul'] })
);
}

function createAppWithCt(appName: string) {
runCLI(`generate @nx/next:app ${appName} --no-interactive --appDir=false`);
runCLI(
Expand Down
18 changes: 18 additions & 0 deletions e2e/react-extensions/src/cypress-component-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ export default Input;
}
}, 300_000);

it('should successfully component test lib being used in app using babel compiler', () => {
runCLI(
`generate @nx/react:cypress-component-configuration --project=${usedInAppLibName} --generate-tests`
);
updateFile(`libs/${usedInAppLibName}/cypress.config.ts`, (content) => {
// apply babel compiler
return content.replace(
'nxComponentTestingPreset(__filename)',
'nxComponentTestingPreset(__filename, {compiler: "babel"})'
);
});
if (runE2ETests()) {
expect(runCLI(`component-test ${usedInAppLibName} --no-watch`)).toContain(
'All specs passed!'
);
}
}, 300_000);

it('should test buildable lib not being used in app', () => {
createFile(
`libs/${buildableLibName}/src/lib/input/input.cy.tsx`,
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/plugins/cypress-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface NxComponentTestingOptions {
*/
ctTargetName?: string;
bundler?: 'vite' | 'webpack';
compiler?: 'swc' | 'babel';
}

export function nxBaseCypressPreset(
Expand Down
2 changes: 1 addition & 1 deletion packages/next/plugins/component-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Able to find CT project, ${!!ctProjectConfig}.`);
assets: buildAssets,
outputPath: buildOuputPath,
outputFileName: 'main.js',
compiler: 'swc',
compiler: options?.compiler || 'swc',
tsConfig: join(
ctExecutorContext.root,
ctProjectConfig.root,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/plugins/component-testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function nxComponentTestingPreset(
const { buildBaseWebpackConfig } = require('./webpack-fallback');
webpackConfig = buildBaseWebpackConfig({
tsConfigPath: findTsConfig(normalizedProjectRootPath),
compiler: 'babel',
compiler: options?.compiler || 'babel',
erenken marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down