Skip to content

Commit 7b9c5df

Browse files
authored
e2e: introduce custom mount which runs cypress component tests in React Strict mode by default (#35134)
1 parent d2a3686 commit 7b9c5df

File tree

92 files changed

+124
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+124
-140
lines changed

apps/react-17-tests-v9/config/cypressWithStrictMode.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

apps/react-17-tests-v9/config/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { join } = require('node:path');
55

66
/**
77
*
8-
* @returns {string} The path to the node_modules directory used by the project
8+
* @returns {{ usedNodeModulesPath: string, workspaceRootNodeModulesPath: string }} The path to the node_modules directory used by the project
99
*/
1010
function getNodeModulesPath() {
1111
const projectRoot = join(__dirname, '..');
@@ -22,7 +22,7 @@ function getNodeModulesPath() {
2222
console.log('Using React from:', reactPath);
2323
console.log('Using ReactDOM from:', reactDomPath);
2424

25-
return usedNodeModulesPath;
25+
return { usedNodeModulesPath, workspaceRootNodeModulesPath: rootNodeModulesPath };
2626
}
2727

2828
module.exports = {

apps/react-17-tests-v9/cypress-react-17.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,5 @@ const specs = [
1616
const config = { ...baseConfig };
1717

1818
config.component.specPattern = specs;
19-
config.component.devServer.webpackConfig.resolve ??= {};
20-
config.component.devServer.webpackConfig.resolve.alias = {
21-
...config.component.devServer.webpackConfig.resolve.alias,
22-
'@cypress/react': path.resolve(__dirname, './config/cypressWithStrictMode.ts'),
23-
};
2419

2520
export default config;

apps/react-17-tests-v9/cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { baseConfig } from '@fluentui/scripts-cypress';
33

44
import { getNodeModulesPath } from './config/utils';
55

6-
const usedNodeModulesPath = getNodeModulesPath();
6+
const { usedNodeModulesPath } = getNodeModulesPath();
77

88
const config = { ...baseConfig };
99

apps/react-17-tests-v9/jest.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const { join } = require('node:path');
66

77
const { getNodeModulesPath } = require('./config/utils');
88

9-
const usedNodeModulesPath = getNodeModulesPath();
10-
const workspacePresetNodeModulesPath = join(__dirname, '../../node_modules');
9+
const { usedNodeModulesPath, workspaceRootNodeModulesPath } = getNodeModulesPath();
1110

1211
// Reading the SWC compilation config and remove the "exclude"
1312
// for the test files to be compiled by SWC
@@ -42,7 +41,7 @@ module.exports = {
4241
'^react-test-renderer$': join(usedNodeModulesPath, './react-test-renderer'),
4342
'^@testing-library/(react|dom)$': join(usedNodeModulesPath, './@testing-library/$1'),
4443
// need to remap to monorepo root as react-hooks is hoisted
45-
'^@testing-library/react-hooks$': join(workspacePresetNodeModulesPath, './@testing-library/react-hooks'),
44+
'^@testing-library/react-hooks$': join(workspaceRootNodeModulesPath, './@testing-library/react-hooks'),
4645
},
4746
transform: {
4847
'^.+\\.tsx?$': ['@swc/jest', swcJestConfig],

apps/react-17-tests-v9/just.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { getNodeModulesPath } = require('./config/utils');
66

77
preset();
88

9-
const usedNodeModulesPath: string = getNodeModulesPath();
9+
const { usedNodeModulesPath } = getNodeModulesPath();
1010

1111
task('type-check', () =>
1212
typeCheckWithConfigOverride(config => {

apps/react-17-tests-v9/src/components/Menu/Menu.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { mount as mountBase } from '@cypress/react';
2+
import { mount as mountBase } from '@fluentui/scripts-cypress';
33
import { Menu, MenuTrigger, MenuPopover, MenuList, MenuItem } from '@fluentui/react-components';
44

55
import { Provider } from '../Provider/Provider';

apps/react-17-tests-v9/src/components/Provider/Provider.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { mount } from '@cypress/react';
2+
import { mount } from '@fluentui/scripts-cypress';
33
import { Button } from '@fluentui/react-components';
44

55
import { Provider } from './Provider';

apps/react-18-tests-v8/config/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { join } = require('node:path');
55

66
/**
77
*
8-
* @returns {string} The path to the node_modules directory used by the project
8+
* @returns {{ usedNodeModulesPath: string, workspaceRootNodeModulesPath: string }} The path to the node_modules directory used by the project
99
*/
1010
function getNodeModulesPath() {
1111
const projectRoot = join(__dirname, '..');
@@ -22,7 +22,7 @@ function getNodeModulesPath() {
2222
console.log('Using React from:', reactPath);
2323
console.log('Using ReactDOM from:', reactDomPath);
2424

25-
return usedNodeModulesPath;
25+
return { usedNodeModulesPath, workspaceRootNodeModulesPath: rootNodeModulesPath };
2626
}
2727

2828
module.exports = {

apps/react-18-tests-v8/cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { registerTsPaths } from '@fluentui/scripts-storybook';
44

55
import { getNodeModulesPath } from './config/utils';
66

7-
const usedNodeModulesPath = getNodeModulesPath();
7+
const { usedNodeModulesPath } = getNodeModulesPath();
88

99
const tsConfigPath = path.resolve(__dirname, '../../tsconfig.base.v8.json');
1010

0 commit comments

Comments
 (0)