Skip to content

Commit 249c094

Browse files
committed
silence errors by default
1 parent eb71a9b commit 249c094

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

packages/selenium-ide/src/neo/IO/filesystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function downloadProject(project) {
8484

8585
function exportProject(project) {
8686
return Manager.validatePluginExport(project).then(() => {
87-
return Selianize(project).catch(err => {
87+
return Selianize(project, { silenceErrors: true }).catch(err => {
8888
const markdown = ParseError(err && err.message || err);
8989
ModalState.showAlert({
9090
title: "Error saving project",

packages/selianize/__tests__/testcase.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,22 @@ describe("test case code emitter", () => {
118118
};
119119
return expect(TestCaseEmitter.emit(test)).rejects.toMatchObject(testErrors);
120120
});
121+
it("should hardcode errors on silenceErrors option", () => {
122+
const test = {
123+
id: "1",
124+
name: "silence",
125+
commands: [
126+
{
127+
command: "doesntExist",
128+
target: "",
129+
value: ""
130+
}
131+
]
132+
};
133+
return expect(TestCaseEmitter.emit(test, { silenceErrors: true })).resolves.toEqual({
134+
name: "silence",
135+
test: "it(\"silence\", async () => {await tests.silence(driver, vars);await driver.getTitle().then(title => {expect(title).toBeDefined();});});",
136+
function: "tests.silence = async function silence(driver, vars) {throw new Error(\"Unknown command doesntExist\");}"
137+
});
138+
});
121139
});

packages/selianize/src/config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
export default {
19+
silenceErrors: false
20+
};
21+

packages/selianize/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ import SuiteEmitter from "./suite";
2020
import TestCaseEmitter from "./testcase";
2121
import CommandEmitter from "./command";
2222
import LocationEmitter from "./location";
23+
import config from "./config";
2324

24-
export default function Selianize(project) {
25+
export default function Selianize(project, _opts) {
26+
const options = { ...config, ..._opts };
2527
return new Promise(async (res, rej) => { // eslint-disable-line no-unused-vars
2628
let result = "";
2729

2830
result += await ConfigurationEmitter.emit(project);
2931

3032
let errors = [];
31-
const tests = (await Promise.all(project.tests.map((test) => TestCaseEmitter.emit(test).catch(e => {
33+
const tests = (await Promise.all(project.tests.map((test) => TestCaseEmitter.emit(test, options).catch(e => {
3234
errors.push(e);
3335
}))));
3436

packages/selianize/src/testcase.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
// under the License.
1717

1818
import CommandEmitter from "./command";
19+
import config from "./config";
1920

2021
const hooks = [];
2122

22-
export function emit(test) {
23+
export function emit(test, options = config) {
2324
return new Promise(async (res, rej) => { // eslint-disable-line no-unused-vars
2425
const hookResults = await Promise.all(hooks.map((hook) => hook(test)));
2526

@@ -33,11 +34,15 @@ export function emit(test) {
3334
let func = `tests.${convertToSnake(test.name)} = async function ${convertToSnake(test.name)}(driver, vars) {`;
3435
let errors = [];
3536
func += (await Promise.all(test.commands.map((command, index) => (CommandEmitter.emit(command).catch(e => {
36-
errors.push({
37-
index: index + 1,
38-
...command,
39-
message: e
40-
});
37+
if (options.silenceErrors) {
38+
return `throw new Error("${e.message}");`;
39+
} else {
40+
errors.push({
41+
index: index + 1,
42+
...command,
43+
message: e
44+
});
45+
}
4146
}))))).join("");
4247
func += "}";
4348

0 commit comments

Comments
 (0)