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

Improve UX around integration testing #1808

Merged
merged 1 commit into from
Mar 27, 2023
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ packages/toolpad-app/public/reactDevtools
packages/toolpad-app/public/runtime
packages/toolpad-app/public/typings.json

examples/*/yarn.lock
examples/*/yarn.lock

.toolpad-generated
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@ _If you're looking into contributing to the docs, follow the [instructions](#bui

1. Open the docs application in the browser [http://localhost:3003/toolpad](http://localhost:3003/toolpad)

## Integration tests

- To run Toolpad on a fixture

```sh
yarn toolpad dev --dev ./path/to/fixture
Copy link
Member

Choose a reason for hiding this comment

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

Really useful, thanks!

```

- To run the tests locally in production mode

```sh
yarn build:release
yarn test:integration --project chromiun
```

- To run the tests locally in dev mode

```sh
yarn dev
```

then run

```sh
TOOLPAD_NEXT_DEV=1 yarn test:integration --project chromiun
```

- Use the `--ui` flag to run the tests interactively

## Sending a pull request

Please have a look at our general guidelines for sending pull requests [here](https://mui-org.notion.site/GitHub-PRs-7112d03a6c4346168090b29a970c0154) and [here](https://github.com/mui/material-ui/blob/master/CONTRIBUTING.md#sending-a-pull-request).
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"test:build": "lerna run build --scope @mui/toolpad-core --scope @mui/toolpad-components --stream",
"test:integration": "playwright test --config ./test/integration/playwright.config.ts",
"test": "jest",
"check-types": "lerna run check-types"
"check-types": "lerna run check-types",
"toolpad": "toolpad"
},
"devDependencies": {
"@mui/monorepo": "https://github.com/mui/material-ui.git",
Expand Down
15 changes: 10 additions & 5 deletions packages/toolpad-app/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ interface RunCommandArgs {
// Whether Toolpad editor is running in debug mode
devMode?: boolean;
port?: number;
dir?: string;
}

async function runApp(cmd: 'dev' | 'start', { devMode = false, port }: RunCommandArgs) {
async function runApp(
cmd: 'dev' | 'start',
{ devMode = false, port, dir = process.cwd() }: RunCommandArgs,
) {
const { execaNode } = await import('execa');
const { default: chalk } = await import('chalk');
const { default: getPort } = await import('get-port');
Expand All @@ -58,14 +62,13 @@ async function runApp(cmd: 'dev' | 'start', { devMode = false, port }: RunComman
const serverPath = path.resolve(__dirname, './server.js');

const cp = execaNode(serverPath, [], {
cwd: process.cwd(),
cwd: dir,
stdio: 'pipe',
env: {
NODE_ENV: devMode ? 'development' : 'production',
TOOLPAD_DIR: toolpadDir,
TOOLPAD_PROJECT_DIR: dir,
TOOLPAD_PORT: String(port),
TOOLPAD_DEV: devMode ? 'true' : 'false',
TOOLPAD_PROJECT_DIR: process.cwd(),
TOOLPAD_CMD: cmd,
FORCE_COLOR: '1',
},
Expand Down Expand Up @@ -139,11 +142,13 @@ export default async function cli(argv: string[]) {
},
);

const command = args._[0];
const command: string | undefined = args._[0];
const dir: string = args._[1];

const runArgs = {
devMode: args['--dev'],
port: args['--port'],
dir,
};

switch (command) {
Expand Down
14 changes: 10 additions & 4 deletions packages/toolpad-app/cli/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import invariant from 'invariant';
async function main() {
const { default: chalk } = await import('chalk');

const projectDir = process.env.TOOLPAD_PROJECT_DIR;

const dir = process.env.TOOLPAD_DIR;
const dev = process.env.TOOLPAD_DEV === 'true';
const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = Number(process.env.TOOLPAD_PORT);

// when using middleware `hostname` and `port` must be provided below
const app = next({ dir, dev, hostname, port });
const handle = app.getRequestHandler();

await app.prepare();

const server = createServer(async (req, res) => {
try {
invariant(req.url, 'request must have a url');
Expand All @@ -42,7 +42,13 @@ async function main() {
});

// eslint-disable-next-line no-console
console.log(`> Toolpad ready on ${chalk.green(`http://${hostname}:${port}`)}`);
console.log(
`${chalk.green('ready')} - toolpad project ${chalk.cyan(projectDir)} ready on ${chalk.cyan(
`http://${hostname}:${port}`,
)}`,
);

await app.prepare();
}

main().catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/playwright/localTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const test = base.extend<
},
{ browserCloser: null }
>({
toolpadDev: !!process.env.TOOLPAD_DEV,
toolpadDev: !!process.env.TOOLPAD_NEXT_DEV,
localAppConfig: [undefined, { option: true }],
localApp: async ({ localAppConfig, toolpadDev }, use) => {
if (!localAppConfig) {
Expand Down