Skip to content

Commit

Permalink
feat(react-18-tests-v8): enable build-less DX for start,test,e2e and …
Browse files Browse the repository at this point in the history
…normalize all test scenarios
  • Loading branch information
Hotell committed Nov 23, 2022
1 parent 5412278 commit cba9aba
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 129 deletions.
7 changes: 2 additions & 5 deletions apps/react-18-tests-v8/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react--legacy"],
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true,
"rules": {
"deprecation/deprecation": "off",
"prefer-const": "off"
}
"rules": {}
}
11 changes: 10 additions & 1 deletion apps/react-18-tests-v8/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-check

const { resolveMergeStylesSerializer } = require('@fluentui/scripts/jest/jest-resources');
const getResolveAlias = require('@fluentui/scripts/webpack/getResolveAlias');

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
Expand All @@ -9,12 +12,18 @@ module.exports = {
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
diagnostics: { warnOnly: true, exclude: ['packages/**'] },
},
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
},

coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
moduleNameMapper: {
'\\.(scss)$': '@fluentui/scripts/jest/jest-style-mock.js',
...getResolveAlias(),
},
snapshotSerializers: [resolveMergeStylesSerializer()],
};
19 changes: 9 additions & 10 deletions apps/react-18-tests-v8/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "@fluentui/react-18-tests-v8",
"description": "React 18 test application",
"version": "1.0.0",
"version": "8.0.0",
"private": true,
"scripts": {
"build": "just-scripts build",
"clean": "just-scripts clean",
"code-style": "just-scripts code-style",
"format": "prettier -w . --ignore-path ../.prettierignore",
"format:check": "yarn format -c",
"e2e": "cypress run --component",
"e2e:local": "cypress open --component",
"lint": "just-scripts lint",
"test": "just-scripts test",
"just": "just-scripts",
"start": "webpack-dev-server --mode=development --config=webpack.config.js",
"lint": "eslint --ext .js,.ts.,.tsx ./src",
"test": "jest --passWithNoTests",
"start": "webpack-dev-server --mode=development",
"type-check": "tsc -b tsconfig.json"
},
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts": "^1.0.0",
"@types/react": "18.0.14",
"@types/react-dom": "18.0.6",
"swc-loader": "^0.2.3"
"@fluentui/scripts": "^1.0.0"
},
"dependencies": {
"@fluentui/react": "^8.103.0",
"@fluentui/react-hooks": "^8.6.14",
"@types/react": "18.0.14",
"@types/react-dom": "18.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"tslib": "^2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion apps/react-18-tests-v8/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ThemeProvider, DefaultButton, PartialTheme, getTheme } from '@fluentui/react';
import { useBoolean } from '@fluentui/react-hooks';
import { ContextualMenuExample } from './components/index';
import { ContextualMenuExample } from './components';

// This app is here as a simple sandbox to render v8 controls inside of an React 18 environment.

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import { mount } from '@cypress/react';

import { ContextualMenuExample } from './ContextualMenuExample';

const menuTriggerSelector = '[type="button"]';
const menuSelector = '[role="menu"]';

describe('ContextualMenu in React 18', () => {
it('renders ContextualMenu when trigger button is clicked', () => {
mount(
<React.StrictMode>
<ContextualMenuExample />
</React.StrictMode>,
);

cy.get(menuTriggerSelector).click().get(menuSelector).should('be.visible');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { ContextualMenuExample } from './ContextualMenuExample';

describe('ContextualMenu in React 18', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(noop);
});

it('should render ContextualMenu when trigger button is clicked', () => {
const { getByRole, queryAllByRole } = render(
<React.StrictMode>
<ContextualMenuExample />
</React.StrictMode>,
);

expect(queryAllByRole('menu').length).toBe(0);

const menuTrigger = getByRole('button');
userEvent.click(menuTrigger);

expect(queryAllByRole('menu').length).toBe(1);
});
});
4 changes: 2 additions & 2 deletions apps/react-18-tests-v8/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"declaration": true,
"declarationDir": "dist/types",
"inlineSources": true,
"types": ["static-assets", "environment", "node"]
"types": ["static-assets", "environment"]
},
"exclude": ["./src/common/**", "**/*.spec.ts", "**/*.spec.tsx", "**/*.test.ts", "**/*.test.tsx"],
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.test.ts", "**/*.test.tsx", "**/*.cy.ts", "**/*.cy.tsx"],
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
}
4 changes: 2 additions & 2 deletions apps/react-18-tests-v8/tsconfig.cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"compilerOptions": {
"jsx": "react",
"isolatedModules": false,
"types": ["node", "cypress", "cypress-storybook/cypress", "cypress-real-events"],
"types": ["node", "cypress", "cypress-real-events"],
"lib": ["ES2019", "dom"]
},
"include": ["./src/**/*.e2e.ts", "./src/**/*.e2e.tsx"]
"include": ["./src/**/*.cy.ts", "./src/**/*.cy.tsx"]
}
48 changes: 40 additions & 8 deletions apps/react-18-tests-v8/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');

const getResolveAlias = require('@fluentui/scripts/webpack/getResolveAlias');

module.exports = () => {
return {
Expand All @@ -12,22 +12,54 @@ module.exports = () => {
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, '../../tsconfig.base.json'),
}),
],
alias: {
react: path.resolve(__dirname, './node_modules/react'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
...getResolveAlias(),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: 'swc-loader',
use: {
// NOTE: swc-loader throws errors on v8 codebase
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
},
{
test: /\.scss$/,
enforce: 'pre',
exclude: [/node_modules/],
use: [
{
loader: '@microsoft/loader-load-themed-styles', // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
options: {
esModule: false,
modules: true,
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: ['autoprefixer'],
},
},
},
{
loader: 'sass-loader',
},
],
},
],
},
Expand Down

0 comments on commit cba9aba

Please sign in to comment.