fix: get port from created server (#11495)

This commit is contained in:
Nikolay Vitkov 2023-12-05 13:12:07 +01:00 committed by GitHub
parent e82cb47623
commit d2f4b9ca53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View File

@ -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"
},
@ -24,7 +24,8 @@
],
"output": [
"lib/**",
"test/build/**"
"test/build/**",
"*.tsbuildinfo"
]
},
"test": {

View File

@ -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);
@ -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 => {
@ -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};

View File

@ -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;

View File

@ -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);
});