Skip to content
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
6 changes: 2 additions & 4 deletions e2e/qwik-nx-e2e/tests/chore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ describe('appGenerator e2e', () => {
});

describe("qwik-nx's compiled package.json", () => {
let project: string;

it("qwik-nx's package.json should contain only expected dependencies", async () => {
const packageJson = readJson('node_modules/qwik-nx/package.json');

expect(packageJson.dependencies).toBeUndefined();
expect(packageJson.peerDependencies).toEqual({
'@nrwl/vite': '~15.6.0',
'@nrwl/vite': '~15.7.2',
'@builder.io/qwik': '^0.17.0',
'@playwright/test': '^1.30.0',
undici: '^5.18.0',
vite: '^4.0.0',
vitest: '^0.25.0',
tslib: '2.4.1',
tslib: '^2.3.0',
});
}, 200000);
});
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"@commitlint/config-angular": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@jscutlery/semver": "^2.29.0",
"@nrwl/cli": "15.6.1",
"@nrwl/cypress": "15.6.1",
"@nrwl/devkit": "15.6.1",
"@nrwl/eslint-plugin-nx": "15.6.1",
"@nrwl/jest": "15.6.1",
"@nrwl/js": "15.6.1",
"@nrwl/linter": "15.6.1",
"@nrwl/nx-plugin": "15.6.1",
"@nrwl/vite": "15.6.1",
"@nrwl/workspace": "15.6.1",
"@nrwl/cli": "15.7.2",
"@nrwl/cypress": "15.7.2",
"@nrwl/devkit": "15.7.2",
"@nrwl/eslint-plugin-nx": "15.7.2",
"@nrwl/jest": "15.7.2",
"@nrwl/js": "15.7.2",
"@nrwl/linter": "15.7.2",
"@nrwl/nx-plugin": "15.7.2",
"@nrwl/vite": "15.7.2",
"@nrwl/workspace": "15.7.2",
"@nxkit/playwright": "^2.1.1",
"@swc-node/register": "^1.4.2",
"@swc/cli": "~0.1.55",
Expand All @@ -54,7 +54,7 @@
"jsonc-eslint-parser": "^2.1.0",
"kill-port": "2.0.1",
"ngx-deploy-npm": "^5.2.0",
"nx": "15.6.1",
"nx": "15.7.2",
"prettier": "^2.8.0",
"pretty-quick": "^3.1.3",
"tcp-port-used": "1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-nx/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"build": {
"implementation": "./src/executors/build/executor",
"schema": "./src/executors/build/schema.json",
"description": "build executor"
"description": "Build a Qwik application."
}
}
}
2 changes: 1 addition & 1 deletion packages/qwik-nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"generators": "./generators.json",
"executors": "./executors.json",
"peerDependencies": {
"@nrwl/vite": "~15.6.0",
"@nrwl/vite": "~15.7.2",
"@builder.io/qwik": "^0.17.0",
"vite": "^4.0.0",
"vitest": "^0.25.0",
Expand Down
105 changes: 89 additions & 16 deletions packages/qwik-nx/src/executors/build/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,39 @@ import { ExecutorContext, runExecutor, Target } from '@nrwl/devkit';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const devkit: { runExecutor: typeof runExecutor } = require('@nrwl/devkit');

enum MockFailTargets {
NoSuccess = 'mock-no-success',
Error = 'mock-error',
}

describe('Build Executor', () => {
let runExecutorPayloads: Target[] = [];

jest.spyOn(devkit, 'runExecutor').mockImplementation((target: Target) =>
Promise.resolve(
(async function* () {
runExecutorPayloads.push(target);
yield { success: true, target }; // yielding target for debugging purposes
})()
)
);
jest.spyOn(devkit, 'runExecutor').mockImplementation((target: Target) => {
if (target.target === MockFailTargets.NoSuccess) {
return Promise.resolve(
(async function* () {
runExecutorPayloads.push(target);
yield { success: false, target }; // yielding target for debugging purposes
})()
);
} else if (target.target === MockFailTargets.Error) {
return Promise.resolve(
// eslint-disable-next-line require-yield
(async function* () {
runExecutorPayloads.push(target);
throw new Error('Something went wrong');
})()
);
} else {
return Promise.resolve(
(async function* () {
runExecutorPayloads.push(target);
yield { success: true, target }; // yielding target for debugging purposes
})()
);
}
});

afterEach(() => {
runExecutorPayloads = [];
Expand All @@ -33,18 +55,69 @@ describe('Build Executor', () => {
runSequence: ['my-app:target1:development', 'my-app:target2'],
};
const iterable = executor(options, context);
await iterable.next();
expect(runExecutorPayloads.map((p) => p.target)).toEqual(['target1']);
await iterable.next();
expect(runExecutorPayloads.map((p) => p.target)).toEqual([
'target1',
'target2',
]);
const result = await iterable.next();
let result = await iterable.next();
expect(result.value?.success).toEqual(true);
expect(runExecutorPayloads).toEqual([
{ project: 'my-app', target: 'target1', configuration: 'development' },
{ project: 'my-app', target: 'target2', configuration: 'production' },
]);
result = await iterable.next();
expect(result.done).toEqual(true);
});

it('should stop execution if executor returned "success: false"', async () => {
const context = {
root: '/root',
projectName: 'my-app',
targetName: 'build',
configurationName: 'production',
} as ExecutorContext;

const target = MockFailTargets.NoSuccess;

const options: BuildExecutorSchema = {
runSequence: [
'my-app:target1:development',
`my-app:${target}`,
'my-app:target2',
],
};
const iterable = executor(options, context);
let result = await iterable.next();
expect(result.value?.success).toEqual(false);
expect(runExecutorPayloads).toEqual([
{ project: 'my-app', target: 'target1', configuration: 'development' },
{ project: 'my-app', target: target, configuration: 'production' },
]);
result = await iterable.next();
expect(result.done).toEqual(true);
});

it('should stop execution if unhandled error occurs', async () => {
const context = {
root: '/root',
projectName: 'my-app',
targetName: 'build',
configurationName: 'production',
} as ExecutorContext;

const target = MockFailTargets.Error;

const options: BuildExecutorSchema = {
runSequence: [
'my-app:target1:development',
`my-app:${target}`,
'my-app:target2',
],
};
const iterable = executor(options, context);
let result = await iterable.next();
expect(result.value?.success).toEqual(false);
expect(runExecutorPayloads).toEqual([
{ project: 'my-app', target: 'target1', configuration: 'development' },
{ project: 'my-app', target: target, configuration: 'production' },
]);
result = await iterable.next();
expect(result.done).toEqual(true);
});
});
20 changes: 13 additions & 7 deletions packages/qwik-nx/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ export default async function* runBuildExecutor(
});

for (const target of configs) {
const step = await runExecutor(target, {}, context);
try {
const step = await runExecutor(target, {}, context);

for await (const result of step) {
if (!result.success) {
return result;
for await (const result of step) {
if (!result.success) {
yield { success: false };
return;
}
}
yield {
success: true,
};
} catch (error) {
console.error(error);
yield { success: false };
return;
}
}

yield { success: true };
}
4 changes: 2 additions & 2 deletions packages/qwik-nx/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/schema",
"version": 2,
"cli": "nx",
"title": "Build executor",
"description": "",
"title": "Qwik Build",
"description": "Builds a Qwik application for production.",
"type": "object",
"properties": {
"runSequence": {
Expand Down
Loading