Skip to content
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

feat(web-test-runner): support nx 17 and 18 #26

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 59 additions & 52 deletions e2e/web-test-runner/src/web-test-runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,77 @@ import { createE2eWorkspace } from '@robby-rabbitman/nx-plus-tools-local-registr
import { execSync } from 'node:child_process';
import { join } from 'node:path';

describe('@robby-rabbitman/nx-plus-web-test-runner', () => {
let workspaceRoot = '';
// TODO: keep in sync with package.json of 'web-test-runner'
// reference it via env or nx devkit?
const nxVersions = ['^17', '^18', '^19'];

beforeAll(() => {
const workspace = createE2eWorkspace({
e2eProjectName: 'web-test-runner-e2e',
});
workspaceRoot = workspace.workspaceRoot;
});
for (const nxVersion of nxVersions) {
describe(`@robby-rabbitman/nx-plus-web-test-runner with nx@${nxVersion}`, () => {
let workspaceRoot = '';

it('should install succesfully', () => {
execSync(`npm i -D @robby-rabbitman/nx-plus-web-test-runner@e2e`, {
cwd: workspaceRoot,
beforeAll(() => {
const workspace = createE2eWorkspace({
e2eProjectName: 'web-test-runner-e2e',
nxVersion,
});
workspaceRoot = workspace.workspaceRoot;
});
execSync('npm ls @robby-rabbitman/nx-plus-web-test-runner', {
cwd: workspaceRoot,
});
});

it("should add the plugin '@robby-rabbitman/nx-plus-web-test-runner/plugin'", () => {
execSync('nx generate @robby-rabbitman/nx-plus-web-test-runner:init', {
cwd: workspaceRoot,
});

const nxJson = readJson<NxJsonConfiguration>(
join(workspaceRoot, 'nx.json'),
);

expect(nxJson.plugins).toContainEqual({
plugin: '@robby-rabbitman/nx-plus-web-test-runner/plugin',
options: {
targetName: 'test',
},
it('should install succesfully', () => {
execSync(`npm i -D @robby-rabbitman/nx-plus-web-test-runner@e2e`, {
cwd: workspaceRoot,
});
execSync('npm ls @robby-rabbitman/nx-plus-web-test-runner', {
cwd: workspaceRoot,
});
});
});

it('should infer the Web Test Runner', () => {
execSync(
'nx generate @nx/js:library --name=some-js-project --linter=none --projectNameAndRootFormat=as-provided --unitTestRunner=none --no-interactive',
{
it("should add the plugin '@robby-rabbitman/nx-plus-web-test-runner/plugin'", () => {
execSync('nx generate @robby-rabbitman/nx-plus-web-test-runner:init', {
cwd: workspaceRoot,
},
);
});

execSync('touch some-js-project/web-test-runner.config.js', {
cwd: workspaceRoot,
const nxJson = readJson<NxJsonConfiguration>(
join(workspaceRoot, 'nx.json'),
);

expect(nxJson.plugins).toContainEqual({
plugin: '@robby-rabbitman/nx-plus-web-test-runner/plugin',
options: {
targetName: 'test',
},
});
});

const project = JSON.parse(
execSync('nx show project some-js-project --json', {
it('should infer the Web Test Runner', () => {
execSync(
'nx generate @nx/js:library --name=some-js-project --linter=none --projectNameAndRootFormat=as-provided --unitTestRunner=none --no-interactive',
{
cwd: workspaceRoot,
},
);

execSync('touch some-js-project/web-test-runner.config.js', {
cwd: workspaceRoot,
encoding: 'utf-8',
}),
) as ProjectConfiguration;
});

const project = JSON.parse(
execSync('nx show project some-js-project --json', {
cwd: workspaceRoot,
encoding: 'utf-8',
}),
) as ProjectConfiguration;

const testTarget = project.targets['test'];
const testTarget = project.targets['test'];

expect(testTarget).toEqual({
configurations: {},
executor: 'nx:run-commands',
options: {
command:
'web-test-runner --config=some-js-project/web-test-runner.config.js',
},
expect(testTarget).toEqual({
configurations: {},
executor: 'nx:run-commands',
options: {
command:
'web-test-runner --config=some-js-project/web-test-runner.config.js',
},
});
});
});
});
}
4 changes: 2 additions & 2 deletions packages/web-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"url": "https://github.com/RobbyRabbitman/nx-plus/issues"
},
"license": "MIT",
"dependencies": {
"peerDependencies": {
"tslib": "^2.3.0",
"@nx/devkit": "^19.3.0"
"@nx/devkit": "^17 || ^18 || ^19"
},
"generators": "./generators.json",
"type": "commonjs",
Expand Down
6 changes: 6 additions & 0 deletions packages/web-test-runner/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CreateNodes,
CreateNodesContextV2,
CreateNodesFunction,
CreateNodesV2,
Expand All @@ -19,6 +20,11 @@ const webTestRunnerCommand = 'web-test-runner';

const defaultTargetName = 'test';

export const createNodes: CreateNodes<WebTestRunnerTargetPluginOptions> = [
webTestRunnerConfigFileNameGlob,
(...args) => createWebTestRunnerTarget(...args),
];

export const createNodesV2: CreateNodesV2<WebTestRunnerTargetPluginOptions> = [
webTestRunnerConfigFileNameGlob,
(webTestRunnerConfigPaths, options, context) => {
Expand Down
Loading