Skip to content

Commit 6027d8d

Browse files
authored
feat(react-18-tests-v8): setup test:integration to run jest test against r18 (#34318)
1 parent bed7fee commit 6027d8d

13 files changed

Lines changed: 87 additions & 21 deletions

File tree

.github/workflows/pr.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ jobs:
130130
affected_count=$(yarn --silent nx show projects -t type-check:integration --affected --verbose false | wc -l | tr -d ' ')
131131
echo "value=$affected_count" >> $GITHUB_OUTPUT
132132
133+
- name: Affected test:integration Projects
134+
id: affected_projects_test_count
135+
run: |
136+
affected_count=$(yarn --silent nx show projects -t test:integration --affected --verbose false | wc -l | tr -d ' ')
137+
echo "value=$affected_count" >> $GITHUB_OUTPUT
138+
133139
- name: type-check (affected)
134140
id: type-check
135141
if: steps.affected_projects_type_check_count.outputs.value > 0
@@ -150,6 +156,15 @@ jobs:
150156
path: tsc-logs
151157
retention-days: 1
152158

159+
# run targets only on affected changes - need to run this outside nx runner context to avoid https://github.com/nrwl/nx/issues/30562
160+
- name: test (affected)
161+
id: test
162+
if: steps.affected_projects_test_count.outputs.value > 0
163+
run: |
164+
yarn nx run-many -p react-${{ matrix.react }}-tests-v${{ matrix.fluentui }} -t build:integration --nxBail
165+
yarn workspace @fluentui/react-${{ matrix.react }}-tests-v${{ matrix.fluentui }} test:integration
166+
continue-on-error: true
167+
153168
# run targets only on affected changes - need to run this outside nx runner context to avoid https://github.com/nrwl/nx/issues/30562
154169
- name: e2e (affected)
155170
id: e2e
@@ -176,14 +191,16 @@ jobs:
176191
echo "" >> $GITHUB_STEP_SUMMARY
177192
echo "- Type-check: ${{ steps.type-check.outcome }}" >> $GITHUB_STEP_SUMMARY
178193
echo "- E2E: ${{ steps.e2e.outcome }}" >> $GITHUB_STEP_SUMMARY
194+
echo "- Test: ${{ steps.test.outcome }}" >> $GITHUB_STEP_SUMMARY
179195
180-
if [[ "${{ steps.type-check.outcome }}" == "success" && "${{ steps.e2e.outcome }}" == "success" ]]; then
196+
if [[ "${{ steps.type-check.outcome }}" == "success" && "${{ steps.e2e.outcome }}" == "success" && "${{ steps.test.outcome }}" == "success" ]]; then
181197
echo "✅ React ${{ matrix.react }} / v${{ matrix.fluentui }} integration tests passed"
182198
exit 0
183199
else
184200
echo "❌ React ${{ matrix.react }} / v${{ matrix.fluentui }} integration tests failed"
185201
echo "Type-check: ${{ steps.type-check.outcome }}"
186202
echo "E2E: ${{ steps.e2e.outcome }}"
203+
echo "Test: ${{ steps.test.outcome }}"
187204
exit 1
188205
fi
189206

apps/react-18-tests-v8/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"root": true,
44
"rules": {
55
"no-restricted-globals": "off",
6-
"import/no-extraneous-dependencies": "off"
6+
"import/no-extraneous-dependencies": "off",
7+
"@fluentui/max-len": "off"
78
}
89
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
/** Jest test setup file. */
22

33
require('@testing-library/jest-dom');
4+
5+
const { initializeIcons } = require('@fluentui/font-icons-mdl2');
6+
// Initialize icons.
7+
initializeIcons('');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
const jestConfig = require('./jest.config');
3+
4+
/**
5+
* @type {import('@jest/types').Config.InitialOptions}
6+
*/
7+
const config = {
8+
...jestConfig,
9+
displayName: 'react-18-tests-v8-integration',
10+
roots: ['<rootDir>/../../packages/react/src', '<rootDir>/../../packages/react-hooks/src'],
11+
};
12+
13+
module.exports = config;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-check
2+
const { join } = require('node:path');
23
const { createV8Config: createConfig } = require('@fluentui/scripts-jest');
34

45
/**
@@ -11,6 +12,18 @@ const config = createConfig({
1112
snapshotSerializers: ['@fluentui/jest-serializer-merge-styles'],
1213
});
1314

15+
const moduleNameMapper = config.moduleNameMapper || {};
16+
17+
config.moduleNameMapper = {
18+
...moduleNameMapper,
19+
'^react$': join(__dirname, '/node_modules/react'),
20+
'^react-dom$': join(__dirname, 'node_modules/react-dom'),
21+
'^react-dom/test-utils$': join(__dirname, 'node_modules/react-dom/test-utils'),
22+
'^react-test-renderer$': join(__dirname, 'node_modules/react-test-renderer'),
23+
'^react-is$': join(__dirname, 'node_modules/react-is'),
24+
'^@testing-library/(react|dom)$': join(__dirname, 'node_modules/@testing-library/$1'),
25+
};
26+
1427
// use default jest config to properly resolve react-18
1528
delete config.moduleDirectories;
1629

apps/react-18-tests-v8/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"e2e:integration": "npx --yes cypress@latest run --component --config-file cypress-react-18.config.ts",
1414
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.ts,.tsx ./src",
1515
"test": "jest --passWithNoTests",
16+
"test:integration": "jest --passWithNoTests -c jest-react-18.config.js",
1617
"start": "webpack-dev-server --mode=development"
1718
},
1819
"devDependencies": {
@@ -29,11 +30,16 @@
2930
"@fluentui/react-cards": "*",
3031
"@fluentui/react-hooks": "*",
3132
"@fluentui/react-examples": "*",
33+
"@fluentui/font-icons-mdl2": "*",
34+
"@testing-library/dom": "^10.1.0",
35+
"@testing-library/react": "^16.0.0",
3236
"@types/react": "18.3.20",
3337
"@types/react-dom": "18.3.6",
3438
"cypress-real-events": "1.14.0",
3539
"react": "18.3.1",
3640
"react-dom": "18.3.1",
41+
"react-test-renderer": "18.3.1",
42+
"react-is": "18.3.1",
3743
"tslib": "^2.1.0"
3844
}
3945
}

apps/react-18-tests-v8/project.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
"e2e:integration": {
1919
"dependsOn": [],
2020
"inputs": ["{projectRoot}/cypress-react-18.config.ts", "{workspaceRoot}/packages/react-examples/**/*.e2e.tsx?"]
21+
},
22+
"test:integration": {
23+
"dependsOn": ["^build"],
24+
"inputs": ["{projectRoot}/jest-react-18.config.js", "{workspaceRoot}/packages/react/**/*.(test|spec).tsx?"]
25+
},
26+
"build:integration": {
27+
"dependsOn": ["^build"],
28+
"inputs": ["{workspaceRoot}/packages/react/**/*.(test|spec).tsx?"]
2129
}
2230
}
2331
}

apps/react-18-tests-v8/src/components/ContextualMenu/ContextualMenuExample.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('ContextualMenu in React 18', () => {
2222
expect(queryAllByRole('menu').length).toBe(0);
2323

2424
const menuTrigger = getByRole('button');
25+
2526
userEvent.click(menuTrigger);
2627

2728
expect(queryAllByRole('menu').length).toBe(1);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
const { join } = require('node:path');
4+
35
/**
46
* @type {import('@jest/types').Config.InitialOptions}
57
*/
@@ -9,8 +11,11 @@ module.exports = {
911
// Heads up!
1012
// Forces React to be resolved from the root node_modules to ensure the same instance is used across all packages
1113
moduleNameMapper: {
12-
'^react$': '<rootDir>/node_modules/react',
13-
'^react-dom$': '<rootDir>/node_modules/react-dom',
14+
'^react$': join(__dirname, '/node_modules/react'),
15+
'^react-dom$': join(__dirname, 'node_modules/react-dom'),
16+
'^react-dom/test-utils$': join(__dirname, 'node_modules/react-dom/test-utils'),
17+
'^react-test-renderer$': join(__dirname, 'node_modules/react-test-renderer'),
18+
'^@testing-library/(react|dom)$': join(__dirname, 'node_modules/@testing-library/$1'),
1419
},
1520
transform: {
1621
'^.+\\.tsx?$': ['@swc/jest', {}],

apps/react-18-tests-v9/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@fluentui/react-nav-preview": "*",
2727
"@testing-library/dom": "^10.1.0",
2828
"@testing-library/react": "^16.0.0",
29-
"@testing-library/user-event": "^14.5.2",
3029
"@types/react": "18.3.20",
3130
"@types/react-dom": "18.3.6",
3231
"@types/react-test-renderer": "18.3.1",

0 commit comments

Comments
 (0)