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

[tests] A better sandboxing of tests and builds #123

Open
wants to merge 6 commits into
base: yoann/add-more-injection-points
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ module.exports = {
],
'no-delete-var': 'error',
'no-label-var': 'error',
'no-shadow': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
'no-shadow-restricted-names': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v4
with:
node-version: '18.19.0'
node-version: '18.x'
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, the setup-node action can be configured to use the exact same version as volta.

Could be handy!

Copy link
Member Author

Choose a reason for hiding this comment

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

super useful, thanks!

- run: yarn install
- run: yarn build:all
- run: yarn typecheck:all
Expand Down
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"**/.yarn/": true,
"**/.yarnrc.yml": true,
"**/yarn.lock": true
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Datadog
Copyright (c) 2025 Datadog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Datadog build-plugins
Copyright 2024-present Datadog, Inc.
Copyright 2025-present Datadog, Inc.

This product includes software developed at Datadog (https://www.datadoghq.com/).
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
"workspaces": [
"packages/*",
"packages/plugins/*",
"packages/published/*",
"packages/tests/src/_jest/fixtures/project"
"packages/published/*"
],
"volta": {
"node": "18.19.0",
"node": "18.20.5",
"yarn": "1.22.19"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const INJECTED_FILE = '__datadog-helper-file';
export const ALL_BUNDLERS = ['webpack', 'vite', 'esbuild', 'rollup', 'rspack', 'rolldown', 'farm'];
export const SUPPORTED_BUNDLERS = ['webpack', 'vite', 'esbuild', 'rollup', 'rspack'] as const;
export const FULL_NAME_BUNDLERS = [
'webpack4',
'webpack5',
'vite',
'esbuild',
'rollup',
'rspack',
'vite',
'webpack4',
'webpack5',
] as const;
9 changes: 2 additions & 7 deletions packages/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('My very awesome plugin', () => {
We currently support `webpack4`, `webpack5`, `esbuild`, `rollup` and `vite`.<br/>
So we need to ensure that our plugin works everywhere.

When you use `runBundlers()` in your setup (usually `beforeAll()`), it will run the build of [a very basic default mock project](/packages/tests/src/_jest/fixtures/main.js).<br/>
When you use `runBundlers()` in your setup (usually `beforeAll()`), it will run the build of [a very basic default mock project](/packages/tests/src/_jest/fixtures/easy_project/main.js).<br/>
Since it's building in a seeded directory, to avoid any collision, it will also return a cleanup function, that you'll need to use in your teardown (usually `afterAll()`).

During development, you may want to target a specific bundler, to reduce noise from the others.<br/>
Expand Down Expand Up @@ -124,7 +124,6 @@ It will return the array of entries it created.
Here's how you'd go with it:

```typescript
import { getWebpack4Entries } from '@dd/tests/_jest/helpers/xpackConfigs';
import { generateProject } from '@dd/tests/_jest/helpers/generateMassiveProject';
import { defaultPluginOptions } from '@dd/tests/_jest/helpers/mocks';
import { runBundlers } from '@dd/tests/_jest/helpers/runBundlers';
Expand All @@ -145,11 +144,7 @@ describe('Some very massive project', () => {
},
// Mode production makes the build waaaaayyyyy too slow.
webpack5: { mode: 'none', entry: entries },
webpack4: {
mode: 'none',
// Webpack4 needs some help for pnp resolutions.
entry: getWebpack4Entries(entries),
},
webpack4: { mode: 'none', entry: entries },
};

cleanup = await runBundlers(defaultPluginOptions, bundlerOverrides);
Expand Down
2 changes: 2 additions & 0 deletions packages/tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ module.exports = {
setupFilesAfterEnv: ['<rootDir>/src/_jest/setupAfterEnv.ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.*'],
// We're building a lot of projects in parallel, so we need to increase the timeout.
testTimeout: 20000,
};
10 changes: 10 additions & 0 deletions packages/tests/src/_jest/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
massiveProject
yarn-error.log
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.vscode

node_modules/
dist/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/tests/src/_jest/fixtures/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compressionLevel: mixed
defaultSemverRangePrefix: ""
enableGlobalCache: false
nodeLinker: node-modules
13 changes: 13 additions & 0 deletions packages/tests/src/_jest/fixtures/easy_project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@tests/easy_project",
"private": true,
"license": "MIT",
"author": "Datadog",
"packageManager": "[email protected]",
"devDependencies": {
"chalk": "2.3.1",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-router-dom": "6.28.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

console.log("Hello injection from local file.");
console.log("Hello injection from local file in after.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

console.log("Hello injection from local file in before.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

console.log("Hello injection from local file in middle.");
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fn2 from './workspaces/app/workspaceFile1.js';
// Add a third party dependency.
import * as chalk from 'chalk';

console.log(chalk.cyan('Hello world!'));
console.log(chalk.cyan('Hello World!'));

fn();
fn2();
15 changes: 15 additions & 0 deletions packages/tests/src/_jest/fixtures/hard_project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@tests/hard_project",
"private": true,
"license": "MIT",
"author": "Datadog",
"packageManager": "[email protected]",
"dependencies": {
"chalk": "2.3.1"
},
"devDependencies": {
"react": "19.0.0",
"react-dom": "19.0.0",
"react-router-dom": "6.28.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "project",
"name": "@tests/fixtures",
"private": true,
"license": "MIT",
"author": "Datadog",
"packageManager": "[email protected]",
"dependencies": {
"chalk": "2.3.1"
}
"workspaces": [
"hard_project",
"easy_project"
]
}
149 changes: 149 additions & 0 deletions packages/tests/src/_jest/fixtures/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 8
cacheKey: 10

"@remix-run/router@npm:1.21.0":
version: 1.21.0
resolution: "@remix-run/router@npm:1.21.0"
checksum: 10/cf0fb69d19c1b79095ff67c59cea89086f3982a9a54c8a993818a60fc76e0ebab5a8db647c1a96a662729fad8e806ddd0a96622adf473f5a9f0b99998b2dbad4
languageName: node
linkType: hard

"@tests/easy_project@workspace:easy_project":
version: 0.0.0-use.local
resolution: "@tests/easy_project@workspace:easy_project"
dependencies:
chalk: "npm:2.3.1"
react: "npm:19.0.0"
react-dom: "npm:19.0.0"
react-router-dom: "npm:6.28.0"
languageName: unknown
linkType: soft

"@tests/fixtures@workspace:.":
version: 0.0.0-use.local
resolution: "@tests/fixtures@workspace:."
languageName: unknown
linkType: soft

"@tests/hard_project@workspace:hard_project":
version: 0.0.0-use.local
resolution: "@tests/hard_project@workspace:hard_project"
dependencies:
chalk: "npm:2.3.1"
react: "npm:19.0.0"
react-dom: "npm:19.0.0"
react-router-dom: "npm:6.28.0"
languageName: unknown
linkType: soft

"ansi-styles@npm:^3.2.0":
version: 3.2.1
resolution: "ansi-styles@npm:3.2.1"
dependencies:
color-convert: "npm:^1.9.0"
checksum: 10/d85ade01c10e5dd77b6c89f34ed7531da5830d2cb5882c645f330079975b716438cd7ebb81d0d6e6b4f9c577f19ae41ab55f07f19786b02f9dfd9e0377395665
languageName: node
linkType: hard

"chalk@npm:2.3.1":
version: 2.3.1
resolution: "chalk@npm:2.3.1"
dependencies:
ansi-styles: "npm:^3.2.0"
escape-string-regexp: "npm:^1.0.5"
supports-color: "npm:^5.2.0"
checksum: 10/53f7346b01d5bd93cceb1645bf3858ef4a211b4c69be152e391cdbe386038308e227c14f5518c4f437cbca72054f0593c19f3ebc75b042892c79f46b0605f60b
languageName: node
linkType: hard

"color-convert@npm:^1.9.0":
version: 1.9.3
resolution: "color-convert@npm:1.9.3"
dependencies:
color-name: "npm:1.1.3"
checksum: 10/ffa319025045f2973919d155f25e7c00d08836b6b33ea2d205418c59bd63a665d713c52d9737a9e0fe467fb194b40fbef1d849bae80d674568ee220a31ef3d10
languageName: node
linkType: hard

"color-name@npm:1.1.3":
version: 1.1.3
resolution: "color-name@npm:1.1.3"
checksum: 10/09c5d3e33d2105850153b14466501f2bfb30324a2f76568a408763a3b7433b0e50e5b4ab1947868e65cb101bb7cb75029553f2c333b6d4b8138a73fcc133d69d
languageName: node
linkType: hard

"escape-string-regexp@npm:^1.0.5":
version: 1.0.5
resolution: "escape-string-regexp@npm:1.0.5"
checksum: 10/6092fda75c63b110c706b6a9bfde8a612ad595b628f0bd2147eea1d3406723020810e591effc7db1da91d80a71a737a313567c5abb3813e8d9c71f4aa595b410
languageName: node
linkType: hard

"has-flag@npm:^3.0.0":
version: 3.0.0
resolution: "has-flag@npm:3.0.0"
checksum: 10/4a15638b454bf086c8148979aae044dd6e39d63904cd452d970374fa6a87623423da485dfb814e7be882e05c096a7ccf1ebd48e7e7501d0208d8384ff4dea73b
languageName: node
linkType: hard

"react-dom@npm:19.0.0":
version: 19.0.0
resolution: "react-dom@npm:19.0.0"
dependencies:
scheduler: "npm:^0.25.0"
peerDependencies:
react: ^19.0.0
checksum: 10/aa64a2f1991042f516260e8b0eca0ae777b6c8f1aa2b5ae096e80bbb6ac9b005aef2bca697969841d34f7e1819556263476bdfea36c35092e8d9aefde3de2d9a
languageName: node
linkType: hard

"react-router-dom@npm:6.28.0":
version: 6.28.0
resolution: "react-router-dom@npm:6.28.0"
dependencies:
"@remix-run/router": "npm:1.21.0"
react-router: "npm:6.28.0"
peerDependencies:
react: ">=16.8"
react-dom: ">=16.8"
checksum: 10/e637825132ea96c3514ef7b8322f9bf0b752a942d6b4ffc4c20e389b5911726adf3dba8208ed4b97bf5b9c3bd465d9d1a1db1a58a610a8d528f18d890e0b143f
languageName: node
linkType: hard

"react-router@npm:6.28.0":
version: 6.28.0
resolution: "react-router@npm:6.28.0"
dependencies:
"@remix-run/router": "npm:1.21.0"
peerDependencies:
react: ">=16.8"
checksum: 10/f021a644513144884a567d9c2dcc432e8e3233f931378c219c5a3b5b842340f0faca86225a708bafca1e9010965afe1a7dada28aef5b7b6138c885c0552d9a7d
languageName: node
linkType: hard

"react@npm:19.0.0":
version: 19.0.0
resolution: "react@npm:19.0.0"
checksum: 10/2490969c503f644703c88990d20e4011fa6119ddeca451e9de48f6d7ab058d670d2852a5fcd3aa3cd90a923ab2815d532637bd4a814add402ae5c0d4f129ee71
languageName: node
linkType: hard

"scheduler@npm:^0.25.0":
version: 0.25.0
resolution: "scheduler@npm:0.25.0"
checksum: 10/e661e38503ab29a153429a99203fefa764f28b35c079719eb5efdd2c1c1086522f6653d8ffce388209682c23891a6d1d32fa6badf53c35fb5b9cd0c55ace42de
languageName: node
linkType: hard

"supports-color@npm:^5.2.0":
version: 5.5.0
resolution: "supports-color@npm:5.5.0"
dependencies:
has-flag: "npm:^3.0.0"
checksum: 10/5f505c6fa3c6e05873b43af096ddeb22159831597649881aeb8572d6fe3b81e798cc10840d0c9735e0026b250368851b7f77b65e84f4e4daa820a4f69947f55b
languageName: node
linkType: hard
Loading
Loading