From f39b8d795c6250629fb51ac69bf8529c124b3a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Thu, 4 Jan 2024 12:38:32 +0100 Subject: [PATCH 1/2] [test] Restore the `t` command --- package.json | 5 +++-- scripts/test.mjs | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 scripts/test.mjs diff --git a/package.json b/package.json index 94474821688f07..25d7bca64d70bb 100644 --- a/package.json +++ b/package.json @@ -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", + "test:cli": "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}'", diff --git a/scripts/test.mjs b/scripts/test.mjs new file mode 100644 index 00000000000000..09c7072615fdae --- /dev/null +++ b/scripts/test.mjs @@ -0,0 +1,15 @@ +import { spawn } from 'node:child_process'; + +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...'); + spawn('pnpm', ['test:cli', ...process.argv.slice(2)], { + shell: true, + stdio: ['inherit', 'inherit', 'inherit'], + }); +} From 386bb61d3c8240eb482aa5876918dd67161ec8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Fri, 5 Jan 2024 11:07:22 +0100 Subject: [PATCH 2/2] Add comments --- package.json | 2 +- scripts/test.mjs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d5e39b31039109..1df2942f435120 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "size:why": "pnpm size:snapshot --analyze", "start": "pnpm install && pnpm docs:dev", "test": "node scripts/test.mjs", - "test:cli": "node test/cli.js", + "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}'", diff --git a/scripts/test.mjs b/scripts/test.mjs index 09c7072615fdae..56a43fa60022a5 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -1,4 +1,15 @@ +/* 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 ` (or `pnpm t `) to run a subset of tests in watch mode. + +See https://github.com/mui/material-ui/pull/40430 for more context. +*/ if (process.argv.length < 3) { console.log('Running ESLint, type checker, and unit tests...'); @@ -8,7 +19,15 @@ if (process.argv.length < 3) { }); } else { console.log('Running selected tests in watch mode...'); - spawn('pnpm', ['test:cli', ...process.argv.slice(2)], { + 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'], });