From fe6c03a5d4e6d974aa9ca89503278fa5eb0527ff Mon Sep 17 00:00:00 2001 From: Jacob Ley Date: Sun, 8 Dec 2024 06:30:44 +0000 Subject: [PATCH] nx-update-ts-references: Create plugin integration test --- .../src/tests/integration/plugin.spec.ts | 83 +++++++++++++++++++ .../update-ts-references/index.spec.ts | 7 -- 2 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 apps/nx-update-ts-references/src/tests/integration/plugin.spec.ts delete mode 100644 apps/nx-update-ts-references/src/tests/unit/executors/update-ts-references/index.spec.ts diff --git a/apps/nx-update-ts-references/src/tests/integration/plugin.spec.ts b/apps/nx-update-ts-references/src/tests/integration/plugin.spec.ts new file mode 100644 index 00000000..d5762d56 --- /dev/null +++ b/apps/nx-update-ts-references/src/tests/integration/plugin.spec.ts @@ -0,0 +1,83 @@ +import Path from 'node:path'; +import { createProjectGraphAsync, type ExecutorContext } from '@nx/devkit'; +import type { Context } from 'mocha'; +import { before, suite } from 'mocha-chain'; +import executor from '../../executors/update-ts-references/index.cjs'; +import { expect } from '../chai-hooks.js'; + +const handler = executor.default; + +suite('plugin', () => { + const withExecutorContext = before(async function (this: Context) { + this.timeout(2000); + const projectGraph = await createProjectGraphAsync(); + return { + projectGraph, + defaultSettings: { + projectName: 'nx-update-ts-references', + root: Path.join(import.meta.dirname, '../../../../..'), + nxJsonConfiguration: {}, + projectsConfigurations: { + version: 123, + projects: {}, + }, + cwd: process.cwd(), + isVerbose: false, + projectGraph, + } satisfies ExecutorContext, + }; + }); + + withExecutorContext.test('success', async ({ defaultSettings }) => { + expect( + await handler( + { + check: true, + dryRun: true, + }, + defaultSettings + ) + ).to.deep.equal({ success: true }); + }); + + suite('Out of sync', () => { + const withInvalidContext = withExecutorContext.before( + ({ defaultSettings, projectGraph }) => ({ + errorSettings: { + ...defaultSettings, + projectGraph: { + ...projectGraph, + dependencies: { + ...projectGraph.dependencies, + 'nx-update-ts-references': [], + }, + }, + }, + }) + ); + + withInvalidContext.test('Fails when check is enabled', async ({ errorSettings }) => { + expect( + await handler( + { + check: true, + dryRun: false, + }, + errorSettings + ) + ).to.deep.equal({ success: false }); + }); + + withInvalidContext.test('Passes when dryRun is enabled', async ({ errorSettings }) => { + expect( + await handler( + { + check: false, + dryRun: true, + }, + errorSettings + ) + ).to.deep.equal({ success: true }); + }); + }); +}); diff --git a/apps/nx-update-ts-references/src/tests/unit/executors/update-ts-references/index.spec.ts b/apps/nx-update-ts-references/src/tests/unit/executors/update-ts-references/index.spec.ts deleted file mode 100644 index 334e60b6..00000000 --- a/apps/nx-update-ts-references/src/tests/unit/executors/update-ts-references/index.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { suite, test } from 'mocha-chain'; - -suite('types', () => { - test('coverage', async () => { - await import('../../../../executors/update-ts-references/index.cjs'); - }); -});