Skip to content

Commit

Permalink
[test] Speed up the envinfo test (#40669)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Jan 29, 2024
1 parent 0492cf2 commit 93f307b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 71 deletions.
42 changes: 9 additions & 33 deletions packages/mui-envinfo/envinfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,24 @@ const { execFileSync } = require('child_process');
const path = require('path');
const { expect } = require('chai');

const isRunningOnWindows = process.platform === 'win32';

describe('@mui/envinfo', () => {
const packagePath = __dirname;
const testProjectPath = path.resolve(packagePath, 'test');

before(function beforeHook() {
// only run in node
if (!/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

// Building might take some time
this.timeout(20000);
execFileSync('pnpm', ['build'], {
cwd: packagePath,
function execEnvinfo(args) {
const envinfoPath = path.resolve(packagePath, 'envinfo.js');
return execFileSync('node', [envinfoPath, ...args], {
encoding: 'utf8',
stdio: 'pipe',
});

execFileSync('npm', ['install'], {
cwd: testProjectPath,
stdio: 'pipe',
});
});

function execEnvinfo(args) {
const buildPath = path.resolve(packagePath, 'build');

return execFileSync(
isRunningOnWindows ? 'npx.cmd' : 'npx',
['--package', buildPath, 'envinfo', ...args],
{
encoding: 'utf8',
stdio: 'pipe',
cwd: testProjectPath,
},
);
}

it('includes info about the environment relevant to MUI', function test() {
// Need more time to download packages
this.timeout(20000);
// only run in node
if (!/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const envinfoJSON = execEnvinfo(['--json']);

Expand All @@ -60,7 +36,7 @@ describe('@mui/envinfo', () => {
// Non-exhaustive list of `@mui/*` packages
expect(envinfo).to.have.nested.property('npmPackages.@mui/material');
expect(envinfo).to.have.nested.property('npmPackages.@mui/joy');
expect(envinfo).to.have.nested.property('npmPackages.@mui/utils');
expect(envinfo).to.have.nested.property('npmPackages.@mui/base');
// Other libraries
expect(envinfo).to.have.nested.property('npmPackages.react');
expect(envinfo).to.have.nested.property('npmPackages.react-dom');
Expand Down
7 changes: 4 additions & 3 deletions packages/mui-envinfo/test/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "test-project",
"name": "envinfo-test-project",
"version": "1.0.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.15.6",
"@mui/joy": "^5.0.0-beta.24",
"@mui/base": "5.0.0-beta.30",
"@mui/joy": "5.0.0-beta.22",
"@mui/material": "5.15.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
151 changes: 117 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
packages:
- 'benchmark'
- 'packages/*'
- '!packages/mui-envinfo/test'
- 'packages/mui-envinfo/test'
- 'docs'
- 'test'
- 'apps/*'

0 comments on commit 93f307b

Please sign in to comment.