From 7eb1d5a47d2809333ac72a940d5bd1b48c97394c Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 11 Dec 2024 13:43:00 +0000 Subject: [PATCH] chore(bundling): fix plugin tests --- .../plugins/__snapshots__/plugin.spec.ts.snap | 109 ++++++++++++++++++ packages/rollup/src/plugins/plugin.spec.ts | 12 +- 2 files changed, 115 insertions(+), 6 deletions(-) diff --git a/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap b/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap index 853336d26330e..9664935cb9e4e 100644 --- a/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap +++ b/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap @@ -55,6 +55,61 @@ exports[`@nx/rollup/plugin non-root project should create nodes 1`] = ` ] `; +exports[`@nx/rollup/plugin non-root project should create nodes 2`] = ` +[ + [ + "mylib/rollup.config.cts", + { + "projects": { + "mylib": { + "root": "mylib", + "targets": { + "build": { + "cache": true, + "command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript", + "dependsOn": [ + "^build", + ], + "inputs": [ + "production", + "^production", + { + "externalDependencies": [ + "rollup", + ], + }, + ], + "metadata": { + "description": "Run Rollup", + "help": { + "command": "npx rollup --help", + "example": { + "options": { + "sourcemap": true, + "watch": true, + }, + }, + }, + "technologies": [ + "rollup", + ], + }, + "options": { + "cwd": "mylib", + }, + "outputs": [ + "{workspaceRoot}/mylib/build", + "{workspaceRoot}/mylib/dist", + ], + }, + }, + }, + }, + }, + ], +] +`; + exports[`@nx/rollup/plugin root project should create nodes 1`] = ` [ [ @@ -108,3 +163,57 @@ exports[`@nx/rollup/plugin root project should create nodes 1`] = ` ], ] `; + +exports[`@nx/rollup/plugin root project should create nodes 2`] = ` +[ + [ + "rollup.config.cts", + { + "projects": { + ".": { + "root": ".", + "targets": { + "build": { + "cache": true, + "command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript", + "dependsOn": [ + "^build", + ], + "inputs": [ + "production", + "^production", + { + "externalDependencies": [ + "rollup", + ], + }, + ], + "metadata": { + "description": "Run Rollup", + "help": { + "command": "npx rollup --help", + "example": { + "options": { + "sourcemap": true, + "watch": true, + }, + }, + }, + "technologies": [ + "rollup", + ], + }, + "options": { + "cwd": ".", + }, + "outputs": [ + "{workspaceRoot}/dist", + ], + }, + }, + }, + }, + }, + ], +] +`; diff --git a/packages/rollup/src/plugins/plugin.spec.ts b/packages/rollup/src/plugins/plugin.spec.ts index 4c18f9c54bb50..a4bb968f716e6 100644 --- a/packages/rollup/src/plugins/plugin.spec.ts +++ b/packages/rollup/src/plugins/plugin.spec.ts @@ -15,7 +15,7 @@ describe('@nx/rollup/plugin', () => { let context: CreateNodesContext; let cwd = process.cwd(); - describe('root project', () => { + describe.each(['js', 'ts'])('root project', (extname) => { const tempFs = new TempFs('test'); beforeEach(() => { @@ -51,7 +51,7 @@ describe('@nx/rollup/plugin', () => { // is that the hash is different after updating the // config file. The actual config read is mocked below. tempFs.createFileSync( - 'rollup.config.cjs', + `rollup.config.c${extname}`, JSON.stringify(rollupConfigOptions) ); tempFs.createFileSync('package.json', JSON.stringify({ name: 'mylib' })); @@ -77,7 +77,7 @@ describe('@nx/rollup/plugin', () => { it('should create nodes', async () => { // ACT const nodes = await createNodesFunction( - ['rollup.config.cjs'], + [`rollup.config.c${extname}`], { buildTargetName: 'build', }, @@ -89,7 +89,7 @@ describe('@nx/rollup/plugin', () => { }); }); - describe('non-root project', () => { + describe.each(['js', 'ts'])('non-root project', (extname) => { const tempFs = new TempFs('test'); beforeEach(() => { @@ -125,7 +125,7 @@ describe('@nx/rollup/plugin', () => { // is that the hash is different after updating the // config file. The actual config read is mocked below. tempFs.createFileSync( - 'mylib/rollup.config.cjs', + `mylib/rollup.config.c${extname}`, JSON.stringify(rollupConfigOptions) ); tempFs.createFileSync( @@ -154,7 +154,7 @@ describe('@nx/rollup/plugin', () => { it('should create nodes', async () => { // ACT const nodes = await createNodesFunction( - ['mylib/rollup.config.cjs'], + [`mylib/rollup.config.c${extname}`], { buildTargetName: 'build', },