Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Restore the t command #40430

Merged
merged 3 commits into from
Jan 5, 2024
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"size:snapshot": "node --max-old-space-size=4096 ./scripts/sizeSnapshot/create",
"size:why": "pnpm size:snapshot --analyze",
"start": "pnpm install && pnpm docs:dev",
"t": "node test/cli.js",
"test": "pnpm eslint && pnpm typescript && pnpm test:coverage",
"test": "node scripts/test.mjs",
"tc": "node test/cli.js",
"test:extended": "pnpm eslint && pnpm typescript && pnpm test:coverage",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=text mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:coverage:ci": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=html mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
Expand Down
34 changes: 34 additions & 0 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-console */
import { spawn } from 'node:child_process';
import chalk from 'chalk';

/*
This script ensures that we can use the same commands to run tests
when using pnpm as when using Yarn.
It enables to run `pnpm test` (or `pnpm t`) without any arguments, to run all tests,
or `pnpm test <test-name>` (or `pnpm t <test-name>`) to run a subset of tests in watch mode.

See https://github.com/mui/material-ui/pull/40430 for more context.
*/

Copy link
Member

@Janpot Janpot Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment here and link to this PR (#40430)? We would likely never have set it up this way if we had started out with pnpm and so that makes the why documented for future generations.

Another thing we could do at some point is add some output saying "pnpm t <pattern> is deprecated, use pnpm tw <pattern> instead. This way of running the tests will be removed in a future version of the MUI core repository". This gives contributors enough time to adapt their muscle memory and us the option of removing the complexity of this script in the future.

if (process.argv.length < 3) {
console.log('Running ESLint, type checker, and unit tests...');
spawn('pnpm', ['test:extended'], {
shell: true,
stdio: ['inherit', 'inherit', 'inherit'],
});
} else {
console.log('Running selected tests in watch mode...');
console.log(
chalk.yellow(
'Note: run `pnpm tc` to have a better experience (and be able to pass in additional parameters).',
),
);

console.log('cmd', ['tc', ...process.argv.slice(2)]);

spawn('pnpm', ['tc', ...process.argv.slice(2)], {
shell: true,
stdio: ['inherit', 'inherit', 'inherit'],
});
}