-
Notifications
You must be signed in to change notification settings - Fork 16
feat: nx-plugin with v2 format #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aramirezj
wants to merge
23
commits into
code-pushup:main
Choose a base branch
from
aramirezj:feat--nx-plugin-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+542
−192
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f987e8a
feat: mvp
aramirezj 9eeca80
chore: wip
aramirezj a2cfed6
chore: wip
aramirezj 9a5c138
chore: wip
aramirezj d8641bb
chore: wip
aramirezj cf57279
chore: wip
aramirezj b39e1eb
chore: wip
aramirezj db535af
chore: wip
aramirezj ed2dae9
chore: create v1-v2 function helpers and tests
aramirezj 3041082
chore: remove unused lint rule
aramirezj b942550
Update packages/nx-plugin/src/plugin/utils.ts
aramirezj 4c2c20d
Update packages/nx-plugin/src/plugin/types.ts
aramirezj a59ee14
chore: add js
aramirezj 7264e6b
test: add e2e for nx-plugin config derivation
BioPhoton 9406d24
test: add new e2e
aramirezj 67ff51d
docs: add v1v2 reference
aramirezj 2241baf
chore: merge main into branch
aramirezj 6a96b9c
chore: fix type name
aramirezj 38efd10
Update testing/test-nx-utils/src/lib/utils/nx-plugin.unit.test.ts
aramirezj d96d239
chore: uncomment code
aramirezj bc523bb
fix: update packages
BioPhoton 8973d23
fix: update packages 2
BioPhoton 2338231
Merge branch 'code-pushup:main' into feat--nx-plugin-v2
aramirezj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
e2e/nx-plugin-e2e/tests/plugin-derive-config.e2e.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { type Tree, writeJson } from '@nx/devkit'; | ||
import path from 'node:path'; | ||
import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; | ||
import { afterEach, expect } from 'vitest'; | ||
import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; | ||
import { | ||
generateProject, | ||
generateWorkspaceAndProject, | ||
materializeTree, | ||
nxShowProjectJson, | ||
nxTargetProject, | ||
registerPluginInWorkspace, | ||
} from '@code-pushup/test-nx-utils'; | ||
import { | ||
E2E_ENVIRONMENTS_DIR, | ||
TEST_OUTPUT_DIR, | ||
teardownTestFolder, | ||
} from '@code-pushup/test-utils'; | ||
|
||
describe('nx-plugin-derived-config', () => { | ||
let root: string; | ||
let tree: Tree; | ||
const projectName = 'pkg'; | ||
const testFileDir = path.join( | ||
E2E_ENVIRONMENTS_DIR, | ||
nxTargetProject(), | ||
TEST_OUTPUT_DIR, | ||
'plugin-create-nodes', | ||
); | ||
|
||
beforeEach(async () => { | ||
tree = await generateWorkspaceAndProject(); | ||
registerPluginInWorkspace(tree, '@code-pushup/nx-plugin'); | ||
await generateProject(tree, projectName); | ||
root = readProjectConfiguration(tree, projectName).root; | ||
generateCodePushupConfig(tree, root); | ||
}); | ||
|
||
afterEach(async () => { | ||
await teardownTestFolder(testFileDir); | ||
}); | ||
|
||
it('should derive config from project.json', async () => { | ||
const cwd = path.join(testFileDir, 'project-config'); | ||
const projectJsonPath = path.join('libs', projectName, 'project.json'); | ||
const packageJsonPath = path.join('libs', projectName, 'package.json'); | ||
tree.delete(projectJsonPath); | ||
tree.delete(packageJsonPath); | ||
writeJson(tree, projectJsonPath, { | ||
root, | ||
name: projectName, | ||
targets: { | ||
'code-pushup': { | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
}, | ||
}, | ||
}, | ||
}); | ||
await materializeTree(tree, cwd); | ||
|
||
const { code, projectJson } = await nxShowProjectJson(cwd, projectName); | ||
expect(code).toBe(0); | ||
|
||
expect(projectJson.targets).toStrictEqual( | ||
expect.objectContaining({ | ||
'code-pushup': { | ||
configurations: {}, | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
}, | ||
parallelism: true, | ||
}, | ||
}), | ||
); | ||
}); | ||
|
||
it('should derive config from package.json', async () => { | ||
const cwd = path.join(testFileDir, 'package-config'); | ||
const projectJsonPath = path.join('libs', projectName, 'project.json'); | ||
const packageJsonPath = path.join('libs', projectName, 'package.json'); | ||
tree.delete(projectJsonPath); | ||
tree.delete(packageJsonPath); | ||
writeJson(tree, packageJsonPath, { | ||
name: `@code-pushup/${projectName}`, | ||
nx: { | ||
root, | ||
name: projectName, | ||
targets: { | ||
'code-pushup': { | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
await materializeTree(tree, cwd); | ||
|
||
const { code, projectJson } = await nxShowProjectJson(cwd, projectName); | ||
expect(code).toBe(0); | ||
|
||
expect(projectJson.targets).toStrictEqual( | ||
expect.objectContaining({ | ||
'code-pushup': { | ||
configurations: {}, | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
}, | ||
parallelism: true, | ||
}, | ||
}), | ||
); | ||
}); | ||
|
||
it('should derive config from mixed', async () => { | ||
const cwd = path.join(testFileDir, 'mixed-config'); | ||
const projectJsonPath = path.join('libs', projectName, 'project.json'); | ||
const packageJsonPath = path.join('libs', projectName, 'package.json'); | ||
|
||
writeJson(tree, projectJsonPath, { | ||
root, | ||
name: projectName, | ||
targets: { | ||
'code-pushup': { | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
}, | ||
}, | ||
}, | ||
}); | ||
writeJson(tree, packageJsonPath, { | ||
name: `@code-pushup/${projectName}`, | ||
nx: { | ||
root, | ||
name: projectName, | ||
targets: { | ||
'code-pushup': { | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.outputPath': 'my-dir', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
await materializeTree(tree, cwd); | ||
|
||
const { code, projectJson } = await nxShowProjectJson(cwd, projectName); | ||
expect(code).toBe(0); | ||
|
||
expect(projectJson.targets).toStrictEqual( | ||
expect.objectContaining({ | ||
'code-pushup': { | ||
configurations: {}, | ||
executor: `@code-pushup/nx-plugin:cli`, | ||
options: { | ||
'persist.filename': 'my-report', | ||
'persist.outputPath': 'my-dir', | ||
}, | ||
parallelism: true, | ||
}, | ||
}), | ||
); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,160 @@ | ||
import type { CreateNodesContext } from '@nx/devkit'; | ||
import type { CreateNodesContext, CreateNodesContextV2 } from '@nx/devkit'; | ||
import { vol } from 'memfs'; | ||
import { describe, expect } from 'vitest'; | ||
import { invokeCreateNodesOnVirtualFiles } from '@code-pushup/test-nx-utils'; | ||
import { | ||
createNodesContextV1, | ||
createNodesContextV2, | ||
invokeCreateNodesOnVirtualFilesV1, | ||
invokeCreateNodesOnVirtualFilesV2, | ||
} from '@code-pushup/test-nx-utils'; | ||
import { PACKAGE_NAME, PROJECT_JSON_FILE_NAME } from '../internal/constants.js'; | ||
import { CP_TARGET_NAME } from './constants.js'; | ||
import { createNodes } from './plugin.js'; | ||
import { createNodes, createNodesV2 } from './plugin.js'; | ||
|
||
describe('@code-pushup/nx-plugin/plugin', () => { | ||
let context: CreateNodesContext; | ||
describe('V1', () => { | ||
let context: CreateNodesContext; | ||
|
||
beforeEach(() => { | ||
context = { | ||
nxJsonConfiguration: {}, | ||
workspaceRoot: '', | ||
configFiles: [], | ||
}; | ||
}); | ||
beforeEach(() => { | ||
context = createNodesContextV1({ | ||
nxJsonConfiguration: {}, | ||
workspaceRoot: '', | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vol.reset(); | ||
}); | ||
afterEach(() => { | ||
vol.reset(); | ||
}); | ||
|
||
it('should normalize context and use it to create the configuration target on ROOT project', async () => { | ||
const projectRoot = '.'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
}; | ||
it('should normalize context and use it to create the configuration target on ROOT project', async () => { | ||
const projectRoot = '.'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
}; | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
createNodes, | ||
context, | ||
{}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[`${CP_TARGET_NAME}--configuration`]: { | ||
command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV1( | ||
createNodes, | ||
context, | ||
{}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[`${CP_TARGET_NAME}--configuration`]: { | ||
command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should normalize context and use it to create the configuration target on PACKAGE project', async () => { | ||
const projectRoot = 'apps/my-app'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
}; | ||
it('should create the executor target on PACKAGE project if configured', async () => { | ||
const projectRoot = 'apps/my-app'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
[`${projectRoot}/code-pushup.config.ts`]: '{}', | ||
}; | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
createNodes, | ||
context, | ||
{}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[`${CP_TARGET_NAME}--configuration`]: { | ||
command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV1( | ||
createNodes, | ||
context, | ||
{ | ||
projectPrefix: 'cli', | ||
}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[CP_TARGET_NAME]: { | ||
executor: `${PACKAGE_NAME}:cli`, | ||
options: { | ||
projectPrefix: 'cli', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should create the executor target on ROOT project if configured', async () => { | ||
const projectRoot = '.'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
[`${projectRoot}/code-pushup.config.ts`]: '{}', | ||
}; | ||
describe('V2', () => { | ||
let context: CreateNodesContextV2; | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
createNodes, | ||
context, | ||
{ | ||
projectPrefix: 'cli', | ||
}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[CP_TARGET_NAME]: { | ||
executor: `${PACKAGE_NAME}:cli`, | ||
options: { | ||
projectPrefix: 'cli', | ||
beforeEach(() => { | ||
context = createNodesContextV2({ | ||
nxJsonConfiguration: {}, | ||
workspaceRoot: '', | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vol.reset(); | ||
}); | ||
|
||
it('should normalize context and use it to create the configuration target on ROOT project', async () => { | ||
const projectRoot = '.'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
}; | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFilesV2( | ||
createNodesV2, | ||
context, | ||
{}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[`${CP_TARGET_NAME}--configuration`]: { | ||
command: `nx g ${PACKAGE_NAME}:configuration --skipTarget --targetName="code-pushup" --project="@org/empty-root"`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should create the executor target on PACKAGE project if configured', async () => { | ||
const projectRoot = 'apps/my-app'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
[`${projectRoot}/code-pushup.config.ts`]: '{}', | ||
}; | ||
it('should create the executor target on PACKAGE project if configured', async () => { | ||
const projectRoot = 'apps/my-app'; | ||
const matchingFilesData = { | ||
[`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ | ||
name: '@org/empty-root', | ||
})}`, | ||
[`${projectRoot}/code-pushup.config.ts`]: '{}', | ||
}; | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
createNodes, | ||
context, | ||
{ | ||
projectPrefix: 'cli', | ||
}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[CP_TARGET_NAME]: { | ||
executor: `${PACKAGE_NAME}:cli`, | ||
options: { | ||
projectPrefix: 'cli', | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV2( | ||
createNodesV2, | ||
context, | ||
{ | ||
projectPrefix: 'cli', | ||
}, | ||
{ matchingFilesData }, | ||
), | ||
).resolves.toStrictEqual({ | ||
[projectRoot]: { | ||
targets: { | ||
[CP_TARGET_NAME]: { | ||
executor: `${PACKAGE_NAME}:cli`, | ||
options: { | ||
projectPrefix: 'cli', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 126 additions & 48 deletions
174
testing/test-nx-utils/src/lib/utils/nx-plugin.unit.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,143 @@ | ||
import * as process from 'node:process'; | ||
import process from 'node:process'; | ||
import { describe, expect } from 'vitest'; | ||
import { | ||
createNodesContext, | ||
invokeCreateNodesOnVirtualFiles, | ||
createNodesContextV1, | ||
createNodesContextV2, | ||
invokeCreateNodesOnVirtualFilesV1, | ||
invokeCreateNodesOnVirtualFilesV2, | ||
} from './nx-plugin.js'; | ||
|
||
describe('createNodesContext', () => { | ||
it('should return a context with the provided options', () => { | ||
const context = createNodesContext({ | ||
workspaceRoot: 'root', | ||
nxJsonConfiguration: { plugins: [] }, | ||
}); | ||
expect(context).toStrictEqual( | ||
expect.objectContaining({ | ||
describe('V1', () => { | ||
describe('createNodesContextV1', () => { | ||
it('should return a context with the provided options', () => { | ||
const context = createNodesContextV1({ | ||
workspaceRoot: 'root', | ||
nxJsonConfiguration: { plugins: [] }, | ||
}), | ||
); | ||
}); | ||
}); | ||
expect(context).toEqual({ | ||
workspaceRoot: 'root', | ||
nxJsonConfiguration: { plugins: [] }, | ||
configFiles: [], | ||
}); | ||
}); | ||
|
||
it('should return a context with defaults', () => { | ||
const context = createNodesContext(); | ||
expect(context).toStrictEqual( | ||
expect.objectContaining({ | ||
it('should return a context with defaults', () => { | ||
const context = createNodesContextV1(); | ||
expect(context).toEqual({ | ||
workspaceRoot: process.cwd(), | ||
nxJsonConfiguration: {}, | ||
}), | ||
); | ||
configFiles: [], | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('invokeCreateNodesOnVirtualFiles', () => { | ||
it('should invoke passed function if matching file is given', async () => { | ||
const createNodesFnSpy = vi.fn().mockResolvedValue({}); | ||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContext(), | ||
{}, | ||
{ | ||
matchingFilesData: { | ||
'**/project.json': JSON.stringify({ | ||
name: 'my-lib', | ||
}), | ||
describe('invokeCreateNodesOnVirtualFilesV1', () => { | ||
it('should invoke passed function if matching file is given', async () => { | ||
const createNodesFnSpy = vi | ||
.fn() | ||
.mockResolvedValue({ projects: { 'my-lib': {} } }); | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV1( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContextV1(), | ||
{}, | ||
{ | ||
matchingFilesData: { | ||
'**/project.json': JSON.stringify({ | ||
name: 'my-lib', | ||
}), | ||
}, | ||
}, | ||
}, | ||
), | ||
).resolves.toStrictEqual({}); | ||
expect(createNodesFnSpy).toHaveBeenCalledTimes(1); | ||
), | ||
).resolves.toStrictEqual({ 'my-lib': {} }); | ||
expect(createNodesFnSpy).toHaveBeenCalledTimes(1); | ||
expect(createNodesFnSpy).toHaveBeenCalledWith( | ||
'**/project.json', | ||
{}, | ||
expect.any(Object), | ||
); | ||
}); | ||
|
||
it('should NOT invoke passed function if matching file is NOT given', async () => { | ||
const createNodesFnSpy = vi.fn().mockResolvedValue({}); | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV1( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContextV1(), | ||
{}, | ||
{ matchingFilesData: {} }, | ||
), | ||
).resolves.toStrictEqual({}); | ||
expect(createNodesFnSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('V2', () => { | ||
describe('createNodesContext', () => { | ||
it('should return a context with the provided options', () => { | ||
const context = createNodesContextV2({ | ||
workspaceRoot: 'root', | ||
nxJsonConfiguration: { plugins: [] }, | ||
}); | ||
expect(context).toEqual({ | ||
workspaceRoot: 'root', | ||
nxJsonConfiguration: { plugins: [] }, | ||
}); | ||
}); | ||
|
||
it('should return a context with defaults', () => { | ||
const context = createNodesContextV2(); | ||
expect(context).toEqual({ | ||
workspaceRoot: process.cwd(), | ||
nxJsonConfiguration: {}, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should NOT invoke passed function if matching file is NOT given', async () => { | ||
const createNodesFnSpy = vi.fn().mockResolvedValue({}); | ||
await expect( | ||
invokeCreateNodesOnVirtualFiles( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContext(), | ||
describe('invokeCreateNodesOnVirtualFilesV2', () => { | ||
it('should invoke passed function if matching file is given', async () => { | ||
const createNodesFnSpy = vi | ||
.fn() | ||
.mockResolvedValue([ | ||
['**/project.json', { projects: { 'my-lib': {} } }], | ||
]); | ||
|
||
await expect( | ||
invokeCreateNodesOnVirtualFilesV2( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContextV2(), | ||
{}, | ||
{ | ||
matchingFilesData: { | ||
'**/project.json': JSON.stringify({ | ||
name: 'my-lib', | ||
}), | ||
}, | ||
}, | ||
), | ||
).resolves.toStrictEqual({ 'my-lib': {} }); | ||
|
||
expect(createNodesFnSpy).toHaveBeenCalledTimes(1); | ||
expect(createNodesFnSpy).toHaveBeenCalledWith( | ||
['**/project.json'], | ||
{}, | ||
{ matchingFilesData: {} }, | ||
), | ||
).resolves.toStrictEqual({}); | ||
expect(createNodesFnSpy).not.toHaveBeenCalled(); | ||
expect.any(Object), | ||
); | ||
}); | ||
|
||
it('should NOT invoke passed function if matching file is NOT given', async () => { | ||
const createNodesFnSpy = vi.fn().mockResolvedValue([]); | ||
await expect( | ||
invokeCreateNodesOnVirtualFilesV2( | ||
[`**/project.json`, createNodesFnSpy], | ||
createNodesContextV2(), | ||
{}, | ||
{ matchingFilesData: {} }, | ||
), | ||
).resolves.toStrictEqual({}); | ||
expect(createNodesFnSpy).toHaveBeenCalledTimes(1); | ||
expect(createNodesFnSpy).toHaveBeenCalledWith([], {}, expect.any(Object)); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.