Skip to content

Commit 1f01c5c

Browse files
committed
fixed circular dependency
1 parent 249c094 commit 1f01c5c

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
import { convertToSnake } from "../src/utils";
19+
20+
describe("convert test names to snake_case", () => {
21+
it("should convert spaces to _", () => {
22+
expect(convertToSnake(" ")).toBe("_");
23+
});
24+
it("should convert arithmetic signs to _", () => {
25+
expect(convertToSnake("+")).toBe("_");
26+
expect(convertToSnake("-")).toBe("_");
27+
expect(convertToSnake("/")).toBe("_");
28+
expect(convertToSnake("*")).toBe("_");
29+
expect(convertToSnake("%")).toBe("_");
30+
});
31+
it("should convert boolean signs to _", () => {
32+
expect(convertToSnake("!")).toBe("_");
33+
expect(convertToSnake("=")).toBe("_");
34+
expect(convertToSnake("&")).toBe("_");
35+
expect(convertToSnake("|")).toBe("_");
36+
expect(convertToSnake(">")).toBe("_");
37+
expect(convertToSnake("<")).toBe("_");
38+
expect(convertToSnake("?")).toBe("_");
39+
});
40+
it("should convert other illegal entities to _", () => {
41+
expect(convertToSnake("\\")).toBe("_");
42+
expect(convertToSnake("@")).toBe("_");
43+
expect(convertToSnake("#")).toBe("_");
44+
expect(convertToSnake("^")).toBe("_");
45+
expect(convertToSnake(";")).toBe("_");
46+
expect(convertToSnake(":")).toBe("_");
47+
expect(convertToSnake(".")).toBe("_");
48+
expect(convertToSnake(",")).toBe("_");
49+
});
50+
it("should convert all braces signs to _", () => {
51+
expect(convertToSnake("(")).toBe("_");
52+
expect(convertToSnake(")")).toBe("_");
53+
expect(convertToSnake("[")).toBe("_");
54+
expect(convertToSnake("]")).toBe("_");
55+
expect(convertToSnake("{")).toBe("_");
56+
expect(convertToSnake("}")).toBe("_");
57+
});
58+
it("should convert all string literals", () => {
59+
expect(convertToSnake("'")).toBe("_");
60+
expect(convertToSnake("\"")).toBe("_");
61+
expect(convertToSnake("`")).toBe("_");
62+
});
63+
});

packages/selianize/src/command.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import LocationEmitter from "./location";
1919
import SelectionEmitter from "./selection";
20-
import { convertToSnake } from "./testcase";
20+
import { convertToSnake } from "./utils";
2121

2222
const emitters = {
2323
open: emitOpen,

packages/selianize/src/testcase.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717

1818
import CommandEmitter from "./command";
1919
import config from "./config";
20+
import { convertToSnake } from "./utils";
2021

2122
const hooks = [];
2223

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

2729
let emittedTest = `it("${test.name}", async () => {`;
2830
emittedTest += hookResults.map((hook) => hook.setup || "").join("");
29-
emittedTest += `await tests.${convertToSnake(test.name)}(driver, vars);`;
31+
emittedTest += `await tests.${testName}(driver, vars);`;
3032
emittedTest += "await driver.getTitle().then(title => {expect(title).toBeDefined();});";
3133
emittedTest += hookResults.map((hook) => hook.teardown || "").join("");
3234
emittedTest += "});";
3335

34-
let func = `tests.${convertToSnake(test.name)} = async function ${convertToSnake(test.name)}(driver, vars) {`;
36+
let func = `tests.${testName} = async function ${testName}(driver, vars) {`;
3537
let errors = [];
3638
func += (await Promise.all(test.commands.map((command, index) => (CommandEmitter.emit(command).catch(e => {
3739
if (options.silenceErrors) {
@@ -51,10 +53,6 @@ export function emit(test, options = config) {
5153
});
5254
}
5355

54-
export function convertToSnake(string) {
55-
return string.replace(/(\s|-)/g, "_");
56-
}
57-
5856
function registerHook(hook) {
5957
hooks.push(hook);
6058
}

packages/selianize/src/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 function convertToSnake(string) {
19+
return string.replace(/(\s|\+|-|\*|\/|\\|%|!|\||&|=|\?|>|<|\(|\)|\[|\]|{|}|@|#|\^|:|;|'|"|`|\.|,)/g, "_");
20+
}

0 commit comments

Comments
 (0)