Skip to content

Commit

Permalink
test(react-norhtstar): use new conformance api to narrow down ts prog…
Browse files Browse the repository at this point in the history
…ram to speed up tests
  • Loading branch information
Hotell committed Apr 26, 2023
1 parent a7df17e commit 49370ed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
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
4 changes: 1 addition & 3 deletions packages/fluentui/react-northstar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
"outDir": "dist/dts",
"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"]
}

0 comments on commit 49370ed

Please sign in to comment.