feat(nextjs): can set compiler when setting up nxComponentTestingPreset (#19171)
This commit is contained in:
parent
9c0e6a1a98
commit
e8b6034b6c
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
cleanupProject,
|
||||||
createFile,
|
createFile,
|
||||||
newProject,
|
newProject,
|
||||||
runCLI,
|
runCLI,
|
||||||
@ -14,6 +15,8 @@ describe('NextJs Component Testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => cleanupProject());
|
||||||
|
|
||||||
it('should test a NextJs app', () => {
|
it('should test a NextJs app', () => {
|
||||||
const appName = uniq('next-app');
|
const appName = uniq('next-app');
|
||||||
createAppWithCt(appName);
|
createAppWithCt(appName);
|
||||||
@ -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 () => {
|
it('should test a NextJs lib', async () => {
|
||||||
const libName = uniq('next-lib');
|
const libName = uniq('next-lib');
|
||||||
createLibWithCt(libName, false);
|
createLibWithCt(libName, false);
|
||||||
@ -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) {
|
function createAppWithCt(appName: string) {
|
||||||
runCLI(`generate @nx/next:app ${appName} --no-interactive --appDir=false`);
|
runCLI(`generate @nx/next:app ${appName} --no-interactive --appDir=false`);
|
||||||
runCLI(
|
runCLI(
|
||||||
|
|||||||
@ -165,6 +165,24 @@ export default Input;
|
|||||||
}
|
}
|
||||||
}, 300_000);
|
}, 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', () => {
|
it('should test buildable lib not being used in app', () => {
|
||||||
createFile(
|
createFile(
|
||||||
`libs/${buildableLibName}/src/lib/input/input.cy.tsx`,
|
`libs/${buildableLibName}/src/lib/input/input.cy.tsx`,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export interface NxComponentTestingOptions {
|
|||||||
*/
|
*/
|
||||||
ctTargetName?: string;
|
ctTargetName?: string;
|
||||||
bundler?: 'vite' | 'webpack';
|
bundler?: 'vite' | 'webpack';
|
||||||
|
compiler?: 'swc' | 'babel';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nxBaseCypressPreset(
|
export function nxBaseCypressPreset(
|
||||||
|
|||||||
@ -104,7 +104,7 @@ Able to find CT project, ${!!ctProjectConfig}.`);
|
|||||||
assets: buildAssets,
|
assets: buildAssets,
|
||||||
outputPath: buildOuputPath,
|
outputPath: buildOuputPath,
|
||||||
outputFileName: 'main.js',
|
outputFileName: 'main.js',
|
||||||
compiler: 'swc',
|
compiler: options?.compiler || 'swc',
|
||||||
tsConfig: join(
|
tsConfig: join(
|
||||||
ctExecutorContext.root,
|
ctExecutorContext.root,
|
||||||
ctProjectConfig.root,
|
ctProjectConfig.root,
|
||||||
|
|||||||
@ -160,7 +160,7 @@ export function nxComponentTestingPreset(
|
|||||||
const { buildBaseWebpackConfig } = require('./webpack-fallback');
|
const { buildBaseWebpackConfig } = require('./webpack-fallback');
|
||||||
webpackConfig = buildBaseWebpackConfig({
|
webpackConfig = buildBaseWebpackConfig({
|
||||||
tsConfigPath: findTsConfig(normalizedProjectRootPath),
|
tsConfigPath: findTsConfig(normalizedProjectRootPath),
|
||||||
compiler: 'babel',
|
compiler: options?.compiler || 'babel',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user