Skip to content

Commit

Permalink
nx-update-ts-references: Create plugin integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLey committed Dec 8, 2024
1 parent b5800d8 commit fe6c03a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 7 deletions.
83 changes: 83 additions & 0 deletions apps/nx-update-ts-references/src/tests/integration/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -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 });
});
});
});

This file was deleted.

0 comments on commit fe6c03a

Please sign in to comment.