Skip to content

Commit 579c160

Browse files
committed
test: add cases for monorepo and build plugins with siteDependencies constraints
1 parent d86f532 commit 579c160

File tree

9 files changed

+116
-4
lines changed

9 files changed

+116
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[plugins]]
2+
package = "netlify-plugin-contextual-env"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "module_plugin",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"description": "test",
6+
"license": "MIT",
7+
"repository": "test",
8+
"dependencies": {
9+
"@netlify/dependency-with-range": "^9.5.4"
10+
}
11+
}

packages/build/tests/plugins_list/fixtures/plugins_compat_site_dependencies_range_monorepo_hoisted/node_modules/@netlify/dependency-with-range/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workspaces": [
3+
"apps/*"
4+
]
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[plugins]]
2+
package = "netlify-plugin-contextual-env"

packages/build/tests/plugins_list/fixtures/plugins_compat_site_dependencies_range_monorepo_not_hoisted/apps/web/node_modules/@netlify/dependency-with-range/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "module_plugin",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"description": "test",
6+
"license": "MIT",
7+
"repository": "test",
8+
"dependencies": {
9+
"@netlify/dependency-with-range": "^9.5.4"
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workspaces": [
3+
"apps/*"
4+
]
5+
}

packages/build/tests/plugins_list/tests.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import cpy from 'cpy'
88

99
const FIXTURES_DIR = fileURLToPath(new URL('fixtures', import.meta.url))
1010

11-
const runWithApiMock = async function (
12-
t,
11+
const runWithApiMockAndGetNormalizedOutput = async function (
1312
fixtureName,
1413
{ testPlugin, response = getPluginsList(testPlugin), ...flags } = {},
1514
status = 200,
@@ -20,18 +19,29 @@ const runWithApiMock = async function (
2019
status,
2120
})
2221
try {
23-
const output = await new Fixture(`./fixtures/${fixtureName}`)
22+
const fixture = new Fixture(`./fixtures/${fixtureName}`)
23+
const output = await fixture
2424
.withFlags({
2525
testOpts: { pluginsListUrl: `${scheme}://${host}`, ...flags.testOpts },
26+
// cwd: fixture.repositoryRoot,
2627
...flags,
2728
})
2829
.runWithBuild()
29-
await t.snapshot(normalizeOutput(output))
30+
return normalizeOutput(output)
3031
} finally {
3132
await stopServer()
3233
}
3334
}
3435

36+
const runWithApiMock = async function (
37+
t,
38+
fixtureName,
39+
{ testPlugin, response = getPluginsList(testPlugin), ...flags } = {},
40+
status = 200,
41+
) {
42+
await t.snapshot(await runWithApiMockAndGetNormalizedOutput(fixtureName, { testPlugin, response, ...flags }, status))
43+
}
44+
3545
// We use a specific plugin in tests. We hardcode its version to keep the tests
3646
// stable even when new versions of that plugin are published.
3747
const getPluginsList = function (testPlugin = DEFAULT_TEST_PLUGIN) {
@@ -289,6 +299,66 @@ test.serial('Plugins can specify non-matching compatibility.siteDependencies ran
289299
})
290300
})
291301

302+
test.serial(
303+
'Plugins can specify matching compatibility.siteDependencies range in monorepo with hoisted node_modules',
304+
async (t) => {
305+
await removeDir(`${FIXTURES_DIR}/plugins_compat_site_dependencies_range_monorepo_hoisted/apps/web/.netlify`)
306+
const normalizedOutput = await runWithApiMockAndGetNormalizedOutput(
307+
'plugins_compat_site_dependencies_range_monorepo_hoisted',
308+
{
309+
testPlugin: {
310+
compatibility: [
311+
{ version: '0.3.0' },
312+
{
313+
version: '0.2.0',
314+
siteDependencies: {
315+
// this is satisfied, so this version should be selected
316+
'@netlify/dependency-with-range': '<10',
317+
},
318+
},
319+
],
320+
},
321+
packagePath: 'apps/web',
322+
},
323+
)
324+
t.true(
325+
normalizedOutput.includes(
326+
'netlify-plugin-contextual-env 0-2-0 from netlify.toml (latest 0-3-0, expected 0-2-0, compatible 0-2-0)',
327+
),
328+
)
329+
},
330+
)
331+
332+
test.serial(
333+
'Plugins can specify matching compatibility.siteDependencies range in monorepo without hoisted node_modules',
334+
async (t) => {
335+
await removeDir(`${FIXTURES_DIR}/plugins_compat_site_dependencies_range_monorepo_not_hoisted/apps/web/.netlify`)
336+
const normalizedOutput = await runWithApiMockAndGetNormalizedOutput(
337+
'plugins_compat_site_dependencies_range_monorepo_not_hoisted',
338+
{
339+
testPlugin: {
340+
compatibility: [
341+
{ version: '0.3.0' },
342+
{
343+
version: '0.2.0',
344+
siteDependencies: {
345+
// this is satisfied, so this version should be selected
346+
'@netlify/dependency-with-range': '<10',
347+
},
348+
},
349+
],
350+
},
351+
packagePath: 'apps/web',
352+
},
353+
)
354+
t.true(
355+
normalizedOutput.includes(
356+
'netlify-plugin-contextual-env 0-2-0 from netlify.toml (latest 0-3-0, expected 0-2-0, compatible 0-2-0)',
357+
),
358+
)
359+
},
360+
)
361+
292362
test.serial('Plugin versions can be feature flagged', async (t) => {
293363
await removeDir(`${FIXTURES_DIR}/plugins_compat_node_version/.netlify`)
294364
await runWithApiMock(t, 'plugins_compat_node_version', {

0 commit comments

Comments
 (0)