Skip to content

Commit

Permalink
fix: get port from created server (#11495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Dec 5, 2023
1 parent e82cb47 commit d2f4b9c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/ng-schematics/package.json
Expand Up @@ -8,7 +8,7 @@
"dev:test": "npm run test --watch",
"dev": "npm run build --watch",
"sandbox:test": "node tools/sandbox.js --test",
"sandbox": "node tools/sandbox.js",
"sandbox": "node tools/sandbox.mjs",
"test": "wireit",
"test:smoke": "wireit"
},
Expand All @@ -24,7 +24,8 @@
],
"output": [
"lib/**",
"test/build/**"
"test/build/**",
"*.tsbuildinfo"
]
},
"test": {
Expand Down
15 changes: 13 additions & 2 deletions packages/ng-schematics/src/builders/puppeteer/index.ts
Expand Up @@ -73,7 +73,11 @@ function updateExecutablePath(command: string, root?: string) {
return normalize(path);
}

async function executeCommand(context: BuilderContext, command: string[]) {
async function executeCommand(
context: BuilderContext,
command: string[],
env: Record<string, any> = {}
) {
let project: JsonObject;
if (context.target) {
project = await context.getProjectMetadata(context.target.project);
Expand All @@ -92,6 +96,10 @@ async function executeCommand(context: BuilderContext, command: string[]) {
cwd: path,
stdio: 'inherit',
shell: true,
env: {
...process.env,
...env,
},
});

child.on('error', message => {
Expand Down Expand Up @@ -166,10 +174,13 @@ async function executeE2ETest(
await executeCommand(context, [`tsc`, '-p', 'e2e/tsconfig.json']);

server = await startServer(options, context);
const result = await server.result;

message('\n Running tests 🧪 ... \n', context);
const testRunnerCommand = getCommandForRunner(options.testRunner);
await executeCommand(context, testRunnerCommand);
await executeCommand(context, testRunnerCommand, {
baseUrl: result['baseUrl'],
});

message('\n 🚀 Test ran successfully! 🚀 ', context, 'success');
return {success: true};
Expand Down
Expand Up @@ -3,7 +3,7 @@ import {before, beforeEach, after, afterEach} from 'node:test';
<% } %>
import * as puppeteer from 'puppeteer';

const baseUrl = '<%= baseUrl %>';
const baseUrl = process.env['baseUrl'] ?? '<%= baseUrl %>';
let browser: puppeteer.Browser;
let page: puppeteer.Page;

Expand Down
2 changes: 1 addition & 1 deletion packages/ng-schematics/tools/sandbox.mjs
Expand Up @@ -199,7 +199,7 @@ async function main() {
});

if (isShell) {
await runNgSchematicsSandbox(getOptions()).catch(error => {
await runNgSchematicsSandbox(options).catch(error => {
console.log('Something went wrong');
console.error(error);
});
Expand Down

0 comments on commit d2f4b9c

Please sign in to comment.