Skip to content

Commit

Permalink
fix(misc): fix misc generation issues with the ts solution setup
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Dec 13, 2024
1 parent 012d4e9 commit df7e3b3
Show file tree
Hide file tree
Showing 41 changed files with 246 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export default defineConfig({

exports[`e2e migrator cypress with project root at "" cypress version >=10 should create a cypress.config.ts file when it does not exist 1`] = `
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run app1:serve' },
webServerCommands: {
default: 'nx run app1:serve',
},
}),
baseUrl: 'http://localhost:4200',
},
Expand Down Expand Up @@ -98,14 +99,15 @@ export default defineConfig({

exports[`e2e migrator cypress with project root at "projects/app1" cypress version >=10 should create a cypress.config.ts file when it does not exist 1`] = `
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'src',
webServerCommands: { default: 'nx run app1:serve' },
webServerCommands: {
default: 'nx run app1:serve',
},
}),
baseUrl: 'http://localhost:4200',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "<%= tsConfigPath %>",
"compilerOptions": {
"outDir": "dist",
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
"outDir": "out-tsc/cypress",
"allowJs": true,
"types": ["cypress", "node"],
"sourceMap": false
Expand All @@ -17,5 +16,5 @@
<%_ if (jsx) { _%>"<%= offsetFromProjectRoot %>**/*.cy.jsx",<%_ } _%>
"<%= offsetFromProjectRoot %>**/*.d.ts"
],
"exclude": ["dist"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>]
"exclude": ["out-tsc", "test-output"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>]
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('Cypress e2e configuration', () => {
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
Expand Down Expand Up @@ -116,7 +115,6 @@ describe('Cypress e2e configuration', () => {
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
Expand Down Expand Up @@ -176,7 +174,6 @@ describe('Cypress e2e configuration', () => {
expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
Expand Down Expand Up @@ -207,7 +204,6 @@ describe('Cypress e2e configuration', () => {
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
Expand Down Expand Up @@ -450,14 +446,15 @@ export default defineConfig({
expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
export default defineConfig({
component: nxComponentTestingPreset(__filename),
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down Expand Up @@ -513,12 +510,13 @@ export default defineConfig({
expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8'))
.toMatchInlineSnapshot(`
"const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand All @@ -544,12 +542,13 @@ export default defineConfig({
expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8'))
.toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'src' }),
...nxE2EPreset(__filename, {
cypressDir: 'src',
}),
baseUrl: 'http://localhost:4200',
},
});
Expand Down
34 changes: 24 additions & 10 deletions packages/cypress/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ export default defineConfig({
);
expect(actual).toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
import { defineConfig } from 'cypress';
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
export default defineConfig({
component: nxComponentTestingPreset(__filename),
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}) }
e2e: {
...nxE2EPreset(__filename, {
"cypressDir": "cypress"
})
}
});
"
`);
Expand Down Expand Up @@ -134,13 +137,16 @@ export default defineConfig({
);
expect(actual).toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
import { defineConfig } from 'cypress';
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
export default defineConfig({
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}),
baseUrl: 'https://example.com' }
e2e: {
...nxE2EPreset(__filename, {
"cypressDir": "cypress"
}),
baseUrl: 'https://example.com'
}
});
"
`);
Expand All @@ -166,12 +172,20 @@ export default defineConfig({
);
expect(actual).toMatchInlineSnapshot(`
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';
import { defineConfig } from 'cypress';
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
export default defineConfig({
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress","webServerCommands":{"default":"my-app:serve","production":"my-app:serve:production"},"ciWebServerCommand":"my-app:serve-static"}) }
e2e: {
...nxE2EPreset(__filename, {
"cypressDir": "cypress",
"webServerCommands": {
"default": "my-app:serve",
"production": "my-app:serve:production"
},
"ciWebServerCommand": "my-app:serve-static"
})
}
});
"
`);
Expand Down
24 changes: 16 additions & 8 deletions packages/cypress/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,40 @@ export async function addDefaultE2EConfig(
let updatedConfigContents = cyConfigContents;

if (testingTypeConfig.length === 0) {
const configValue = `nxE2EPreset(__filename, ${JSON.stringify(options)})`;
const configValue = `nxE2EPreset(__filename, ${JSON.stringify(
options,
null,
2
)
.split('\n')
.join('\n ')})`;

updatedConfigContents = tsquery.replace(
cyConfigContents,
`${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`,
(node: ObjectLiteralExpression) => {
let baseUrlContents = baseUrl ? `,\nbaseUrl: '${baseUrl}'` : '';
let baseUrlContents = baseUrl ? `,\n baseUrl: '${baseUrl}'` : '';
if (node.properties.length > 0) {
return `{
${node.properties.map((p) => p.getText()).join(',\n')},
e2e: { ...${configValue}${baseUrlContents} }
e2e: {
...${configValue}${baseUrlContents}
}
}`;
}
return `{
e2e: { ...${configValue}${baseUrlContents} }
e2e: {
...${configValue}${baseUrlContents}
}
}`;
}
);

return isCommonJS
? `const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
${updatedConfigContents}`
${updatedConfigContents}`
: `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
${updatedConfigContents}`;
${updatedConfigContents}`;
}
return updatedConfigContents;
}
Expand Down
14 changes: 1 addition & 13 deletions packages/expo/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,6 @@ describe('app', () => {
`);
expect(readJson(tree, 'my-app/tsconfig.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"jsx": "react-native",
"lib": [
"dom",
"esnext",
],
"moduleResolution": "node",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
},
"extends": "../tsconfig.base.json",
"files": [],
"include": [],
Expand Down Expand Up @@ -410,6 +397,7 @@ describe('app', () => {
],
},
"exclude": [
"out-tsc",
"dist",
"**/*.test.ts",
"**/*.spec.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
<%_ if (!isTsSolutionSetup) { _%>
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react-native",
Expand All @@ -10,6 +11,7 @@
"strict": true,
"declaration": true
},
<%_ } _%>
"files": [],
"include": [],
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Normalize Options', () => {
rootProject: false,
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'my-app-e2e',
isTsSolutionSetup: false,
} as NormalizedSchema);
});

Expand Down Expand Up @@ -70,6 +71,7 @@ describe('Normalize Options', () => {
rootProject: false,
e2eProjectName: 'myApp-e2e',
e2eProjectRoot: 'myApp-e2e',
isTsSolutionSetup: false,
} as NormalizedSchema);
});

Expand Down Expand Up @@ -102,6 +104,7 @@ describe('Normalize Options', () => {
rootProject: false,
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'directory-e2e',
isTsSolutionSetup: false,
} as NormalizedSchema);
});

Expand Down Expand Up @@ -133,6 +136,7 @@ describe('Normalize Options', () => {
rootProject: false,
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'directory/my-app-e2e',
isTsSolutionSetup: false,
} as NormalizedSchema);
});

Expand Down Expand Up @@ -165,6 +169,7 @@ describe('Normalize Options', () => {
rootProject: false,
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'my-app-e2e',
isTsSolutionSetup: false,
} as NormalizedSchema);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
determineProjectNameAndRootOptions,
ensureProjectName,
} from '@nx/devkit/src/generators/project-name-and-root-utils';
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { Schema } from '../schema';

export interface NormalizedSchema extends Schema {
Expand All @@ -14,6 +15,7 @@ export interface NormalizedSchema extends Schema {
rootProject: boolean;
e2eProjectName: string;
e2eProjectRoot: string;
isTsSolutionSetup: boolean;
}

export async function normalizeOptions(
Expand Down Expand Up @@ -59,5 +61,6 @@ export async function normalizeOptions(
rootProject,
e2eProjectName,
e2eProjectRoot,
isTsSolutionSetup: isUsingTsSolutionSetup(host),
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"extends": "<%= rootTsConfigPath %>",
<%_ if (!isUsingTsSolutionConfig) { _%>
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
<%_ } _%>
"files": [],
"include": [],
"references": [
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function expoLibraryGeneratorInternal(
updateLibPackageNpmScope(host, options);
}

if (!options.skipTsConfig) {
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
addTsConfigPath(host, options.importPath, [
joinPathFragments(
options.projectRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ describe('app', () => {
`);
expect(readJson(appTree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {
"esModuleInterop": true,
},
"extends": "../tsconfig.base.json",
"files": [],
"include": [],
Expand Down Expand Up @@ -266,6 +263,7 @@ describe('app', () => {
],
},
"exclude": [
"out-tsc",
"dist",
"jest.config.ts",
"src/**/*.spec.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/<%= fileName %>';
export * from './lib/<%= fileNameImport %>';
Loading

0 comments on commit df7e3b3

Please sign in to comment.