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

wip: [example-browser] Change backend startup method #3961

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build_script:
- yarn

test_script:
- yarn run test
- yarn run test:browser

notifications:
- provider: Webhook
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/test/main-page/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MainPage {
}

waitForStartup(): void {
this.driver.waitUntil(() => !this.driver.isExisting('.theia-preload'));
this.driver.waitUntil(() => this.driver.isExisting('.theia-preload'));
paul-marechal marked this conversation as resolved.
Show resolved Hide resolved
}

mainContentPanelExists(): boolean {
Expand Down
66 changes: 45 additions & 21 deletions examples/browser/wdio.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const http = require('http');
const path = require('path');
const temp = require('temp');

const wdioRunnerScript = require.resolve('webdriverio/build/lib/runner.js');
const cp = require('child_process');

// Remove .track() if you'd like to keep the workspace and other temporary
// files after running the tests.
Expand Down Expand Up @@ -190,24 +189,47 @@ function makeConfig(headless) {
// resolved to continue.
//
// Gets executed once before all workers get launched.
onPrepare: function (config, capabilities) {
// Modify process.argv so that the server (which is in the
// master process) starts with a temporary directory as the
// workspace.
onPrepare: async function (config, capabilities) {
const rootDir = temptrack.mkdirSync();
const argv = [process.argv[0], 'src-gen/backend/server.js', '--root-dir=' + rootDir];
return require('./src-gen/backend/server')(port, host, argv).then(created => {
this.execArgv = [wdioRunnerScript, cliPortKey, created.address().port,
const argv = ['--no-cluster', '--root-dir=' + rootDir, '--port=' + port.toString()];

let server;
try {
server = await new Promise((resolve, reject) => {
const process = cp.fork('./src-gen/backend/main.js', argv);

process.once('message', port => {
resolve({
process,
port,
});
});

process.once('error', error => {
console.error(`An error happened within the Theia server process: ${error}`);
reject(error);
});
});
} catch (error) {
console.error('onPrepare ERROR:', error);
return undefined;
}
if (server) {
process.argv.push(cliPortKey, server.port,
'--theia-root-dir', rootDir
];
this.server = created;
});
);
this.server = server.process;
}
},
// Gets executed after all workers got shut down and the process is about to exit. It is not
// possible to defer the end of the process using a promise.
onComplete: function (exitCode) {
if (this.server) {
this.server.close();
try {
this.server.kill();
} catch (error) {
console.error(`Error when trying to kill the server process: ${error}`);
}
}
},
//
Expand Down Expand Up @@ -257,19 +279,21 @@ function makeConfig(headless) {
var fs = require("fs");
let result;
try {
result = browser.execute("return window.__coverage__;");
} catch (error) {
console.error(`Error retreiving the coverage: ${error}`);
result = browser.execute('return window.__coverage__;');
} catch (err) {
console.error(`Coverage report extraction failed: ${err}`);
return;
}
try {
if (!fs.existsSync('coverage')) {
fs.mkdirSync('coverage');
if (result.value) {
if (!fs.existsSync('coverage')) {
fs.mkdirSync('coverage');
}
fs.writeFileSync('coverage/coverage.json', JSON.stringify(result.value));
}
fs.writeFileSync('coverage/coverage.json', JSON.stringify(result.value));
} catch (err) {
console.error(`Error writing coverage ${err}`);
};
console.error(`Error writing coverage: ${err}`);
}
},
//
// Gets executed after all tests are done. You still have access to all global variables from
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"typedoc": "^0.13.0",
"typescript": "^3.1.3",
"uuid": "^3.1.0",
"wdio-mocha-framework": "0.5.9",
"wdio-selenium-standalone-service": "0.0.8",
"wdio-spec-reporter": "0.1.0",
"webdriverio": "4.9.2"
"wdio-mocha-framework": "0.6.4",
"wdio-selenium-standalone-service": "0.0.11",
"wdio-spec-reporter": "0.1.5",
"webdriverio": "4.14.1"
},
"scripts": {
"prepare": "yarn prepare:travis && yarn prepare:hoisting && yarn rebuild:clean && yarn build:clean",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/messaging/messaging-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class MessagingContribution implements BackendApplicationContribution, Me

protected createChannel(id: number, socket: ws): WebSocketChannel {
return new WebSocketChannel(id, content => {
if (socket.readyState < ws.CLOSING) {
if (socket.readyState === ws.OPEN) {
paul-marechal marked this conversation as resolved.
Show resolved Hide resolved
socket.send(content, err => {
if (err) {
throw err;
Expand Down
Loading