Skip to content

Commit 449bcda

Browse files
committed
selianize code in the runner prior to running a project
1 parent 8ef2e1f commit 449bcda

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

packages/selenium-side-runner/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"js-yaml": "^3.10.0",
3636
"rimraf": "^2.6.2",
3737
"selenium-webdriver": "^3.6.0",
38+
"selianize": "*",
3839
"winston": "^2.4.0"
3940
},
4041
"devDependencies": {

packages/selenium-side-runner/src/index.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import program from "commander";
2525
import winston from "winston";
2626
import rimraf from "rimraf";
2727
import { js_beautify as beautify } from "js-beautify";
28+
import Selianize from "selianize";
2829
import Capabilities from "./capabilities";
2930
import Config from "./config";
3031
import metadata from "../package.json";
@@ -101,7 +102,7 @@ configuration.baseUrl = program.baseUrl ? program.baseUrl : configuration.baseUr
101102
let projectPath;
102103

103104
function runProject(project) {
104-
if (!project.code || project.version !== "1.0") {
105+
if (project.version !== "1.0") {
105106
return Promise.reject(new TypeError(`The project ${project.name} is of older format, open and save it again using the IDE.`));
106107
}
107108
projectPath = `side-suite-${project.name}`;
@@ -118,56 +119,59 @@ function runProject(project) {
118119
},
119120
dependencies: project.dependencies || {}
120121
}));
121-
const tests = project.code.tests.reduce((tests, test) => {
122-
return tests += test.code;
123-
}, "const tests = {};").concat("module.exports = tests;");
124-
writeJSFile(path.join(projectPath, "commons"), tests, ".js");
125-
project.code.suites.forEach(suite => {
126-
if (!suite.tests) {
127-
// not parallel
128-
const cleanup = suite.persistSession ? "" : "beforeEach(() => {vars = {};});afterEach(async () => (cleanup()));";
129-
writeJSFile(path.join(projectPath, suite.name), `// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${suite.code}${cleanup}`);
130-
} else if (suite.tests.length) {
131-
fs.mkdirSync(path.join(projectPath, suite.name));
132-
// parallel suite
133-
suite.tests.forEach(test => {
134-
writeJSFile(path.join(projectPath, suite.name, test.name), `// This file was generated using Selenium IDE\nconst tests = require("../commons.js");${suite.code}${test.code}`);
135-
});
136-
}
137-
});
138-
winston.info(`Running ${project.name}`);
139122

140-
return new Promise((resolve, reject) => {
141-
let npmInstall;
142-
if (project.dependencies && Object.keys(project.dependencies).length) {
143-
npmInstall = new Promise((resolve, reject) => {
144-
const child = fork(require.resolve("./npm"), { cwd: path.join(process.cwd(), projectPath), stdio: "inherit" });
123+
return Selianize(project, { silenceErrors: true }).then((code) => {
124+
const tests = code.tests.reduce((tests, test) => {
125+
return tests += test.code;
126+
}, "const tests = {};").concat("module.exports = tests;");
127+
writeJSFile(path.join(projectPath, "commons"), tests, ".js");
128+
code.suites.forEach(suite => {
129+
if (!suite.tests) {
130+
// not parallel
131+
const cleanup = suite.persistSession ? "" : "beforeEach(() => {vars = {};});afterEach(async () => (cleanup()));";
132+
writeJSFile(path.join(projectPath, suite.name), `// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${code.globalConfig}${suite.code}${cleanup}`);
133+
} else if (suite.tests.length) {
134+
fs.mkdirSync(path.join(projectPath, suite.name));
135+
// parallel suite
136+
suite.tests.forEach(test => {
137+
writeJSFile(path.join(projectPath, suite.name, test.name), `// This file was generated using Selenium IDE\nconst tests = require("../commons.js");${code.globalConfig}${suite.code}${test.code}`);
138+
});
139+
}
140+
});
141+
winston.info(`Running ${project.name}`);
142+
143+
return new Promise((resolve, reject) => {
144+
let npmInstall;
145+
if (project.dependencies && Object.keys(project.dependencies).length) {
146+
npmInstall = new Promise((resolve, reject) => {
147+
const child = fork(require.resolve("./npm"), { cwd: path.join(process.cwd(), projectPath), stdio: "inherit" });
148+
child.on("exit", (code) => {
149+
if (code) {
150+
reject();
151+
} else {
152+
resolve();
153+
}
154+
});
155+
});
156+
} else {
157+
npmInstall = Promise.resolve();
158+
}
159+
npmInstall.then(() => {
160+
const child = fork(require.resolve("./child"), [
161+
"--testMatch", `{**/*${program.filter}*/*.test.js,**/*${program.filter}*.test.js}`
162+
].concat(program.maxWorkers ? ["-w", program.maxWorkers] : []), { cwd: path.join(process.cwd(), projectPath), stdio: "inherit" });
163+
145164
child.on("exit", (code) => {
165+
console.log("");
166+
rimraf.sync(projectPath);
146167
if (code) {
147168
reject();
148169
} else {
149170
resolve();
150171
}
151172
});
152-
});
153-
} else {
154-
npmInstall = Promise.resolve();
155-
}
156-
npmInstall.then(() => {
157-
const child = fork(require.resolve("./child"), [
158-
"--testMatch", `{**/*${program.filter}*/*.test.js,**/*${program.filter}*.test.js}`
159-
].concat(program.maxWorkers ? ["-w", program.maxWorkers] : []), { cwd: path.join(process.cwd(), projectPath), stdio: "inherit" });
160-
161-
child.on("exit", (code) => {
162-
console.log("");
163-
rimraf.sync(projectPath);
164-
if (code) {
165-
reject();
166-
} else {
167-
resolve();
168-
}
169-
});
170-
}).catch(reject);
173+
}).catch(reject);
174+
});
171175
});
172176
}
173177

0 commit comments

Comments
 (0)