Skip to content

Commit

Permalink
chore(v0): enable emit only dts and use new conformance test API to n…
Browse files Browse the repository at this point in the history
…arrow down TS Program (#27686)

* chore(v0): emit dts only for v0 which uses babel for transpilation

* test(react-norhtstar): use new conformance api to narrow down ts program to speed up tests

* feat(scripts-jest): clear and restore mocks automatically to prevent accidental test leaks

* test(react-northstar): scope fake timers usage
  • Loading branch information
Hotell authored Apr 27, 2023
1 parent 8232a5a commit 933b40d
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 31 deletions.
5 changes: 3 additions & 2 deletions packages/fluentui/e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"isolatedModules": false,
"noEmit": true,
"emitDeclarationOnly": false,
"module": "esnext",
"types": ["node", "webpack-env", "cypress", "cypress-real-events"],
"skipLibCheck": true
"types": ["node", "webpack-env", "cypress", "cypress-real-events"]
},
"include": ["."]
}
1 change: 1 addition & 0 deletions packages/fluentui/perf/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../../tsconfig.base.v0.json",
"compilerOptions": {
"noEmit": true,
"emitDeclarationOnly": false,
"module": "esnext",
"types": ["node", "webpack-env"]
},
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/projects-test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"allowSyntheticDefaultImports": true,
"module": "esnext",
"types": ["node"],
"skipLibCheck": true,
"outDir": "dist/dts",
"noEmit": true,
"emitDeclarationOnly": false,
"composite": true
},
"include": ["src"],
Expand Down
18 changes: 15 additions & 3 deletions packages/fluentui/react-northstar/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const path = require('path');
const fs = require('fs');
const { workspaceRoot } = require('@nrwl/devkit');
const { pathsToModuleNameMapper } = require('ts-jest');
const { createV0Config: commonConfig } = require('@fluentui/scripts-jest');

const config = commonConfig({
name: 'react',
displayName: 'react-northstar',
moduleNameMapper: {
// Legacy aliases, they should not be used in new tests
'^src/(.*)$': `<rootDir>/src/$1`,
'test/(.*)$': `<rootDir>/test/$1`,
...getAliases(),
},
});
config.setupFilesAfterEnv = [...config.setupFilesAfterEnv, './jest-setup.js'];

module.exports = config;

function getAliases() {
const tsConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'tsconfig.spec.json')));
const tsPathAliases = pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
prefix: `<rootDir>/${path.relative(__dirname, workspaceRoot)}/`,
});

return tsPathAliases;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import * as path from 'path';
import { TestObject } from '@fluentui/react-conformance';
import type { TestObject } from '@fluentui/react-conformance';

import * as doctrine from 'doctrine';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as FluentUI from 'src/index';
import { getEventTargetComponent, EVENT_TARGET_ATTRIBUTE } from './eventTarget';
import { extraConformanceTests } from './extraConformanceTests';

export interface Conformant<TProps = {}>
interface Conformant<TProps = {}>
extends Pick<IsConformantOptions<TProps>, 'disabledTests' | 'testOptions' | 'getTargetElement'> {
/** Path to the test file. */
testPath: string;
Expand Down Expand Up @@ -75,6 +75,7 @@ export function isConformant(
} = options;

const defaultConfig: IsConformantOptions = {
tsConfig: { configName: 'tsconfig.spec.json' },
renderOptions: { wrapper: EmptyThemeProvider },
componentPath: testPath
.replace(/test[/\\]specs/, 'src')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const getNavigationNavigationItemAtIndexWrapper = (wrapper: ReactWrapper, index:
findIntrinsicElement(wrapper, `.${carouselNavigationItemClassName}`).at(index);
const getButtonWrapper = (wrapper: ReactWrapper): CommonWrapper => findIntrinsicElement(wrapper, `#${buttonName}`);

jest.useFakeTimers();

describe('Carousel', () => {
isConformant(Carousel, {
testPath: __filename,
Expand Down Expand Up @@ -244,6 +242,8 @@ describe('Carousel', () => {
items: items.map(item => ({ key: item.key, icon: { name: 'icon-circle' } })),
};

jest.useFakeTimers();

afterEach(() => {
jest.runAllTimers();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ShorthandValue } from 'src/types';
import { List } from 'src/components/List/List';

jest.dontMock('@fluentui/keyboard-key');
jest.useFakeTimers();

describe('Dropdown', () => {
isConformant(Dropdown, {
Expand Down Expand Up @@ -327,6 +326,7 @@ describe('Dropdown', () => {
});

describe('highlightedIndex', () => {
jest.useFakeTimers();
afterEach(() => {
act(() => {
jest.runAllTimers();
Expand Down Expand Up @@ -1292,6 +1292,7 @@ describe('Dropdown', () => {
});

describe('getA11ySelectionMessage', () => {
jest.useFakeTimers();
afterEach(() => {
jest.runAllTimers();
});
Expand Down
5 changes: 1 addition & 4 deletions packages/fluentui/react-northstar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
"compilerOptions": {
"composite": true,
"outDir": "dist/dts",
"skipLibCheck": true,
"types": ["node", "jest", "@testing-library/jest-dom"],
"paths": {
"docs/*": ["packages/fluentui/docs/*"],
"src/*": ["packages/fluentui/react-northstar/src/*"],
"test/*": ["packages/fluentui/react-northstar/test/*"],
"@fluentui/a11y-testing": ["packages/a11y-testing/src/index"]
"test/*": ["packages/fluentui/react-northstar/test/*"]
}
},
"include": ["src", "test"],
Expand Down
14 changes: 14 additions & 0 deletions packages/fluentui/react-northstar/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"emitDeclarationOnly": false,
"composite": false,
"types": ["node", "jest", "@testing-library/jest-dom"],
"paths": {
"src/*": ["packages/fluentui/react-northstar/src/*"],
"test/*": ["packages/fluentui/react-northstar/test/*"]
}
},
"include": ["test"]
}
2 changes: 2 additions & 0 deletions scripts/jest/src/jest.preset.v0.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const createConfig = (/** @type {import('@jest/types').Config.InitialOptions} */
verbose: false,
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
testEnvironment: 'jsdom',
restoreMocks: true,
clearMocks: true,
...customConfig,
moduleNameMapper: {
...getLernaAliases({
Expand Down
16 changes: 1 addition & 15 deletions scripts/jest/src/v0/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@
* This is the bootstrap code that is run before any tests, utils, mocks.
*/

const enzyme = require('enzyme');
const Adapter = require('@wojtekmaj/enzyme-adapter-react-17');
const enzyme = require('enzyme');

enzyme.configure({
adapter: new Adapter(),
disableLifecycleMethods: true,
});

if (process.env.TF_BUILD) {
jest.spyOn(console, 'log');
jest.spyOn(console, 'info');
jest.spyOn(console, 'warn');
jest.spyOn(console, 'error');

afterAll(() => {
expect(console.log).not.toHaveBeenCalled();
expect(console.info).not.toHaveBeenCalled();
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
}
1 change: 1 addition & 0 deletions tsconfig.base.v0.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"jsx": "react",
"isolatedModules": true,
"moduleResolution": "node",
"emitDeclarationOnly": true,
"pretty": true,
"allowJs": false,
"noImplicitReturns": true,
Expand Down

0 comments on commit 933b40d

Please sign in to comment.