Skip to content

Commit

Permalink
Add --build=1 param for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Oct 25, 2024
1 parent fa96ab4 commit 7296030
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
10 changes: 8 additions & 2 deletions packages/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,16 @@ For this, you can use the `--bundlers=<name>,<name>` flag when running your test
yarn test:noisy packages/tests/... --bundlers=webpack4,esbuild
```

Builds are automatically cleaned up after a run, but if you want to keep them for debugging purpose, you can use the `--no-cleanup` flag:
If you want to keep the built files for debugging purpose, you can use the `--cleanup=0` parameter:

```bash
yarn test:noisy packages/tests/... --no-cleanup
yarn test:noisy packages/tests/... --cleanup=0
```

If you want to also build the bundlers you're targeting, you can use the `--build=1` parameter:

```bash
yarn test:noisy packages/tests/... --build=1
```

### More complex projects
Expand Down
7 changes: 6 additions & 1 deletion packages/tests/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export const BUNDLER_VERSIONS: Record<BundlerFullName, string> = {
webpack5: require('webpack5').version,
};

export const NO_CLEANUP = process.argv.includes('--no-cleanup');
export const NO_CLEANUP = process.argv.includes('--cleanup=0');
if (NO_CLEANUP) {
console.log(bgYellow(" Won't clean up "));
}

export const NEED_BUILD = process.argv.includes('--build=1');
if (NEED_BUILD) {
console.log(bgYellow(' Will also build used plugins '));
}
16 changes: 14 additions & 2 deletions packages/tests/src/helpers/runBundlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright 2019-Present Datadog, Inc.

import type { BundlerFullName, Options } from '@dd/core/types';
import { bgYellow, green, red } from '@dd/tools/helpers';
import { bgYellow, executeSync, green, red } from '@dd/tools/helpers';
import type { BuildOptions } from 'esbuild';
import { remove } from 'fs-extra';
import path from 'path';
Expand All @@ -18,7 +18,7 @@ import {
getWebpack4Options,
getWebpack5Options,
} from './configBundlers';
import { NO_CLEANUP, PLUGIN_VERSIONS } from './constants';
import { NEED_BUILD, NO_CLEANUP, PLUGIN_VERSIONS } from './constants';
import { defaultDestination } from './mocks';
import type { Bundler, BundlerRunFunction, CleanupFn } from './types';

Expand Down Expand Up @@ -270,6 +270,18 @@ export const BUNDLERS: Bundler[] = allBundlers.filter(
(bundler) => specificBundlers.length === 0 || specificBundlers.includes(bundler.name),
);

// Build only if needed.
if (NEED_BUILD) {
const bundlersToBuild = new Set(
BUNDLERS.map((bundler) => `@datadog/${bundler.name.replace(/\d/g, '')}-plugin`),
);

for (const bundler of bundlersToBuild) {
console.log(`Building ${green(bundler)}...`);
executeSync('yarn', ['workspace', bundler, 'run', 'build']);
}
}

export const runBundlers = async (
pluginOverrides: Partial<Options> = {},
bundlerOverrides: Record<string, any> = {},
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { GetPlugins } from '@dd/core/types';
import chalk from 'chalk';
import { execFile } from 'child_process';
import { execFile, execFileSync } from 'child_process';
import fs from 'fs-extra';
import path from 'path';
import { promisify } from 'util';
Expand All @@ -26,6 +26,9 @@ const maxBuffer = 1024 * 1024;
export const execute = (cmd: string, args: string[], cwd: string = ROOT) =>
execFileP(cmd, args, { maxBuffer, cwd, encoding: 'utf-8' });

export const executeSync = (cmd: string, args: string[], cwd: string = ROOT) =>
execFileSync(cmd, args, { maxBuffer, cwd, encoding: 'utf-8' });

export const slugify = (string: string) => {
return string
.toString()
Expand Down

0 comments on commit 7296030

Please sign in to comment.