Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/pigment-css-vite-app/src/Slider/ZeroSlider.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals expect */
import { render } from '@testing-library/react';
import { render } from '@testing-library/react/pure';
import Slider from './ZeroSlider';

describe('Slider', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/pigment-css-vite-app/src/pages/fixtures/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function main() {
it(`creates screenshots of ${route}`, async function test() {
// With the playwright inspector we might want to call `page.pause` which would lead to a timeout.
if (process.env.PWDEBUG) {
this.timeout(0);
this?.timeout?.(0);
}

const testcase = await renderFixture(index);
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"@netlify/functions": "^4.2.5",
"@slack/bolt": "^4.4.0",
"babel-plugin-transform-import-meta": "^2.3.3",
"execa": "^9.6.0"
"execa": "^9.6.0",
"karma-spec-reporter": "^0.0.36"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.2",
Expand All @@ -126,6 +127,7 @@
"@types/babel__core": "^7.20.5",
"@types/babel__register": "^7.17.3",
"@types/lodash": "^4.17.20",
"@types/lodash.kebabcase": "^4.1.9",
"@types/mocha": "^10.0.10",
"@types/node": "^20.19.11",
"@types/react": "^19.1.11",
Expand Down Expand Up @@ -161,6 +163,7 @@
"karma-webpack": "^5.0.0",
"lerna": "^8.2.3",
"lodash": "^4.17.21",
"lodash.kebabcase": "^4.1.1",
"markdownlint-cli2": "^0.18.1",
"mocha": "^11.7.1",
"nx": "^20.8.2",
Expand All @@ -171,6 +174,7 @@
"pretty-quick": "^4.2.2",
"process": "^0.11.10",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"rimraf": "^6.0.1",
"serve": "^14.2.4",
"stylelint": "^16.23.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestOptions } from '../../types';
import { TestOptions } from '../types';

const options: TestOptions = {
injector: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestOptions } from '../../types';
import { TestOptions } from '../types';

const options: TestOptions = {
injector: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { TestOptions } from '../../types';
import { TestOptions } from '../types';

const options: TestOptions = {
injector: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestOptions } from '../../types';
import { TestOptions } from '../types';

const options: TestOptions = {
injector: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vite/client" />
import path from 'path';
import fs from 'fs';
import * as ts from 'typescript';
Expand All @@ -11,7 +12,7 @@ import { getPropTypesFromFile } from '../src/getPropTypesFromFile';
import { TestOptions } from './types';

const testCases = glob
.sync('**/input.{d.ts,ts,tsx}', { absolute: true, cwd: __dirname })
.sync('*/input.{d.ts,ts,tsx}', { absolute: true, cwd: __dirname })
.map((testPath) => {
const dirname = path.dirname(testPath);
const name = path.dirname(path.relative(__dirname, testPath));
Expand All @@ -32,9 +33,10 @@ describe('typescript-to-proptypes', () => {
return cachedProject;
}

// @ts-expect-error Second argument is vitest
before(function beforeHook() {
// Creating a TS program might take a while.
this.timeout(20000);
this?.timeout?.(20000);

const buildProject = createTypeScriptProjectBuilder({
test: {
Expand All @@ -52,7 +54,7 @@ describe('typescript-to-proptypes', () => {
// testCases.map((testCase) => testCase.inputPath),
// ttp.loadConfig(path.resolve(__dirname, '../tsconfig.json')),
// );
});
}, 20000);

testCases.forEach((testCase) => {
const { name: testName, inputPath, inputJS, outputPath } = testCase;
Expand All @@ -61,7 +63,7 @@ describe('typescript-to-proptypes', () => {
const project = getProject();
let options: TestOptions = {};
try {
const optionsModule = await import(`./${testName}/options`);
const optionsModule: any = await import(`./${testName}/options.ts`);
options = optionsModule.default;
} catch (error) {
// Assume "Cannot find module" which means "no options".
Expand Down
8 changes: 8 additions & 0 deletions packages-internal/test-utils/src/chai-augmentation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable import/prefer-default-export */
import 'chai';
import type { AssertionError as RealAssertionError } from 'assertion-error';

declare module 'chai' {
// Looks like they forgot to export the AssertionError type in @types/chai
export const AssertionError: typeof RealAssertionError;
}
18 changes: 9 additions & 9 deletions packages-internal/test-utils/src/chaiPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { isInaccessible } from '@testing-library/dom';
import { prettyDOM } from '@testing-library/react/pure';
import type chaiType from 'chai';
import { AssertionError } from 'chai';
import * as chai from 'chai';
import { computeAccessibleDescription, computeAccessibleName } from 'dom-accessibility-api';
import formatUtil from 'format-util';
import _ from 'lodash';
// avoid loading whole lodash, it takes ~50ms to initialize
import kebabCase from 'lodash.kebabcase';
import './chai.types';

const isKarma = Boolean(process.env.KARMA);

function isInJSDOM() {
return /jsdom/.test(window.navigator.userAgent);
return window.navigator.userAgent.includes('jsdom');
}

// chai#utils.elToString that looks like stringified elements in testing-library
Expand All @@ -21,7 +21,7 @@ function elementToString(element: Element | null | undefined) {
return String(element);
}

const chaiPlugin: Parameters<(typeof chaiType)['use']>[0] = (chaiAPI, utils) => {
const chaiPlugin: Parameters<typeof chai.use>[0] = (chaiAPI, utils) => {
const blockElements = new Set([
'html',
'address',
Expand Down Expand Up @@ -202,7 +202,7 @@ const chaiPlugin: Parameters<(typeof chaiType)['use']>[0] = (chaiAPI, utils) =>
// This is closer to actual CSS and required for getPropertyValue anyway.
const expectedStyle: Record<string, string> = {};
Object.keys(expectedStyleUnnormalized).forEach((cssProperty) => {
const hyphenCasedPropertyName = _.kebabCase(cssProperty);
const hyphenCasedPropertyName = kebabCase(cssProperty);
const isVendorPrefixed = /^(moz|ms|o|webkit)-/.test(hyphenCasedPropertyName);
const propertyName = isVendorPrefixed
? `-${hyphenCasedPropertyName}`
Expand Down Expand Up @@ -279,7 +279,7 @@ const chaiPlugin: Parameters<(typeof chaiType)['use']>[0] = (chaiAPI, utils) =>

const jsdomHint =
'Styles in JSDOM e.g. from `test:unit` are often misleading since JSDOM does not implement the Cascade nor actual CSS property value computation. ' +
'If results differ between real browsers and JSDOM, skip the test in JSDOM e.g. `if (/jsdom/.test(window.navigator.userAgent)) this.skip();`';
'If results differ between real browsers and JSDOM, skip the test in JSDOM e.g. `if (window.navigator.userAgent.includes("jsdom")) this.skip();`';
const shorthandHint =
'Browsers can compute shorthand properties differently. Prefer longhand properties e.g. `borderTopColor`, `borderRightColor` etc. instead of `border` or `border-color`.';
const messageHint = `${jsdomHint}\n${shorthandHint}`;
Expand Down Expand Up @@ -316,7 +316,7 @@ const chaiPlugin: Parameters<(typeof chaiType)['use']>[0] = (chaiAPI, utils) =>
const element = utils.flag(this, 'object') as HTMLElement;
if (element?.nodeType !== 1) {
// Same pre-condition for negated and unnegated assertion
throw new AssertionError(`Expected an Element but got ${String(element)}`);
throw new chai.AssertionError(`Expected an Element but got ${String(element)}`);
}

assertMatchingStyles.call(this, element.style, expectedStyleUnnormalized, {
Expand All @@ -331,7 +331,7 @@ const chaiPlugin: Parameters<(typeof chaiType)['use']>[0] = (chaiAPI, utils) =>
const element = utils.flag(this, 'object') as HTMLElement;
if (element?.nodeType !== 1) {
// Same pre-condition for negated and unnegated assertion
throw new AssertionError(`Expected an Element but got ${String(element)}`);
throw new chai.AssertionError(`Expected an Element but got ${String(element)}`);
}
const computedStyle = element.ownerDocument.defaultView!.getComputedStyle(element);

Expand Down
17 changes: 11 additions & 6 deletions packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ function testThemeStyleOverrides(
) {
describe('theme style overrides:', () => {
it("respect theme's styleOverrides custom state", async function test(t = {}) {
if (/jsdom/.test(window.navigator.userAgent)) {
if (window.navigator.userAgent.includes('jsdom')) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down Expand Up @@ -831,7 +831,7 @@ function testThemeStyleOverrides(
});

it("respect theme's styleOverrides slots", async function test(t = {}) {
if (/jsdom/.test(window.navigator.userAgent)) {
if (window.navigator.userAgent.includes('jsdom')) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down Expand Up @@ -944,7 +944,7 @@ function testThemeStyleOverrides(
});

it('overrideStyles does not replace each other in slots', async function test(t = {}) {
if (/jsdom/.test(window.navigator.userAgent)) {
if (window.navigator.userAgent.includes('jsdom')) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down Expand Up @@ -1027,7 +1027,7 @@ function testThemeVariants(
) {
describe('theme variants:', () => {
it("respect theme's variants", async function test(t = {}) {
if (/jsdom/.test(window.navigator.userAgent)) {
if (window.navigator.userAgent.includes('jsdom')) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down Expand Up @@ -1084,7 +1084,7 @@ function testThemeVariants(
});

it('supports custom variant', async function test(t = {}) {
if (/jsdom/.test(window.navigator.userAgent)) {
if (window.navigator.userAgent.includes('jsdom')) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down Expand Up @@ -1140,7 +1140,12 @@ function testThemeCustomPalette(
describe('theme extended palette:', () => {
it('should render without errors', function test(t = {}) {
const { render, ThemeProvider, createTheme } = getOptions();
if (!/jsdom/.test(window.navigator.userAgent) || !render || !ThemeProvider || !createTheme) {
if (
!window.navigator.userAgent.includes('jsdom') ||
!render ||
!ThemeProvider ||
!createTheme
) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() ?? t?.skip();
Expand Down
2 changes: 1 addition & 1 deletion packages-internal/test-utils/src/fireDiscreteEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure, fireEvent, getConfig } from '@testing-library/react';
import { configure, fireEvent, getConfig } from '@testing-library/react/pure';
import reactMajor from './reactMajor';

const noWrapper = (callback: () => void) => callback();
Expand Down
4 changes: 3 additions & 1 deletion packages-internal/test-utils/src/focusVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { act, fireEvent } from './createRenderer';
export default function focusVisible(element: HTMLElement) {
act(() => {
element.blur();
fireEvent.keyDown(document.body, { key: 'Tab' });
});
fireEvent.keyDown(document.body, { key: 'Tab' });
act(() => {
element.focus();
});
}
Expand Down
10 changes: 7 additions & 3 deletions packages-internal/test-utils/src/initPlaywrightMatchers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chai, { AssertionError } from 'chai';
import * as chai from 'chai';
import * as DomTestingLibrary from '@testing-library/dom';
import type { ElementHandle } from '@playwright/test';

Expand Down Expand Up @@ -33,7 +33,9 @@ chai.use((chaiAPI, utils) => {
chai.Assertion.addMethod('toHaveFocus', async function elementHandleIsFocused() {
const $elementOrHandle: ElementHandle | Promise<ElementHandle> = utils.flag(this, 'object');
if ($elementOrHandle == null) {
throw new AssertionError(`Expected an element handle but got ${String($elementOrHandle)}.`);
throw new chai.AssertionError(
`Expected an element handle but got ${String($elementOrHandle)}.`,
);
}
const $element =
typeof ($elementOrHandle as Promise<any>).then === 'function'
Expand Down Expand Up @@ -66,7 +68,9 @@ chai.use((chaiAPI, utils) => {
async function elementHandleHasAttribute(attributeName: string, attributeValue?: string) {
const $elementOrHandle: ElementHandle | Promise<ElementHandle> = utils.flag(this, 'object');
if ($elementOrHandle == null) {
throw new AssertionError(`Expected an element handle but got ${String($elementOrHandle)}.`);
throw new chai.AssertionError(
`Expected an element handle but got ${String($elementOrHandle)}.`,
);
}
const $element =
typeof ($elementOrHandle as Promise<any>).then === 'function'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import extractImports from './extractImports';
import extractImports from './extractImports.mjs';

describe('extractImports', () => {
it('finds all imports', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getCodeblock,
renderMarkdown,
createRender,
} from './parseMarkdown';
} from './parseMarkdown.mjs';

describe('parseMarkdown', () => {
describe('getTitle', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import prepareMarkdown from './prepareMarkdown';
import prepareMarkdown from './prepareMarkdown.mjs';

describe('prepareMarkdown', () => {
const defaultParams = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { parseInline as renderInlineMarkdown } from 'marked';
import textToHash from './textToHash';
import textToHash from './textToHash.mjs';

describe('textToHash', () => {
it('should hash as expected', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@material-ui/core": "^4.12.4",
"@mui/material-v5": "npm:@mui/[email protected]",
"@types/chai": "^4.3.20",
"@types/jscodeshift": "0.12.0",
"chai": "^6.0.1"
Expand Down
7 changes: 0 additions & 7 deletions packages/mui-codemod/src/v4.0.0/optimal-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { dirname } from 'path';
import addImports from 'jscodeshift-add-imports';
import getJSExports from '../util/getJSExports';

// istanbul ignore next
if (process.env.NODE_ENV === 'test') {
const resolve = require.resolve;
require.resolve = (source) =>
resolve(source.replace(/^@material-ui\/core\/es/, '../../../mui-material/src'));
}

export default function transformer(fileInfo, api, options) {
const j = api.jscodeshift;
const importModule = options.importModule || '@material-ui/core';
Expand Down
6 changes: 1 addition & 5 deletions packages/mui-codemod/src/v4.0.0/top-level-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export default function transformer(fileInfo, api, options) {
const importModule = options.importModule || '@material-ui/core';
const targetModule = options.targetModule || '@material-ui/core';

let requirePath = importModule;

if (process.env.NODE_ENV === 'test') {
requirePath = requirePath.replace(/^@material-ui\/core/, '../../../mui-material/src');
}
const requirePath = importModule;

// eslint-disable-next-line global-require, import/no-dynamic-require
const whitelist = require(requirePath);
Expand Down
11 changes: 0 additions & 11 deletions packages/mui-codemod/src/v5.0.0/optimal-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import { dirname } from 'path';
import addImports from 'jscodeshift-add-imports';
import getJSExports from '../util/getJSExports';

// istanbul ignore next
if (process.env.NODE_ENV === 'test') {
const resolve = require.resolve;
require.resolve = (source) =>
resolve(
source
.replace(/^@material-ui\/core\/es/, '../../../mui-material/src')
.replace(/^@material-ui\/core\/modern/, '../../../mui-material/src'),
);
}

export default function transformer(fileInfo, api, options) {
const j = api.jscodeshift;
const importModule = options.importModule || '@material-ui/core';
Expand Down
Loading
Loading