Skip to content

Commit

Permalink
test(nx-heroku): add plugin unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 12, 2024
1 parent 1301231 commit 54aa606
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/nx-heroku/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-disable max-lines-per-function */
import { CreateNodesContext } from '@nx/devkit';
import { tmpProjPath } from '@nx/plugin/testing';

import { createNodes } from './plugin';

jest.mock('node:fs', () => ({
...jest.requireActual('node:fs'),
existsSync: jest.fn(() => false),
readdirSync: jest.fn(() => ['project.json']),
readFileSync: jest.fn(() => 'web: node dist/apps/proj'),
}));

describe('@nx/jest/plugin', () => {
const createNodesFunction = createNodes[1];
const testProjectName = 'proj';
let context: CreateNodesContext;

beforeEach(() => {
context = {
nxJsonConfiguration: {
namedInputs: {
default: ['{projectRoot}/**/*'],
production: ['!{projectRoot}/**/*.spec.ts'],
},
},
workspaceRoot: tmpProjPath(),
};
});

afterEach(() => {
jest.resetModules();
});

it('should create nodes based on Procfile', async () => {
const nodes = await createNodesFunction(
`${testProjectName}/Procfile`,
{
deployTargetName: 'deploy-me',
promoteTargetName: 'promote-me',
},
context
);
expect(nodes.projects[testProjectName]).toMatchInlineSnapshot(`
{
"root": "${testProjectName}",
"targets": {
"deploy-me": {
"cache": false,
"executor": "@aloes/nx-heroku:deploy",
"inputs": [
"default",
"^production",
],
"options": {
"procfile": "web: node dist/apps/proj",
},
},
"promote-me": {
"cache": false,
"executor": "@aloes/nx-heroku:promote",
"inputs": [
"default",
"^production",
],
"options": {},
},
},
}
`);
});
});

0 comments on commit 54aa606

Please sign in to comment.