31 | {this.state.submitted &&
The form was successfully submitted!
}
32 |
68 |
69 |
70 |
TestSpan
71 |
TestDivText
72 |
73 |
74 |
75 | );
76 | }
77 | }
78 |
79 | export default App;
80 |
--------------------------------------------------------------------------------
/packages/cyphfell/src/util/FilePathUtil.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const url = require("url");
3 |
4 | class FilePathUtil {
5 |
6 | /**
7 | * Finds the real path of the specified file if it exists
8 | * @param {String} path - the path to the file without necessarily including an extension
9 | * @return {String} - the path to the file with an extension if found, the path to the index.js file inside a directory if it exists and the input
10 | * path was to that directory, or the input path if not found
11 | */
12 | static findPathWithExtension(path) {
13 | if (!fs.existsSync(path)) {
14 | if (fs.existsSync(`${path}.js`)) {
15 | return `${path}.js`;
16 | } else if (fs.existsSync(`${path}.json`)) {
17 | return `${path}.json`;
18 | }
19 | } else if (fs.lstatSync(path).isDirectory()) {
20 | if (fs.existsSync(`${path}/index.js`)) {
21 | return `${path}/index.js`;
22 | }
23 | }
24 | return path;
25 | }
26 |
27 | /**
28 | * Finds the absolute path to read a file in this module's local directory structure
29 | * @param {String} localPath - the path relative to the current working directory
30 | * @return {String} - the absolute path to the file
31 | */
32 | static findLocalFilePath(localPath) {
33 | if (process.env.TESTING_LOCALLY === "true") {
34 | return `${process.cwd()}/${localPath}`;
35 | }
36 | return `${process.cwd()}/node_modules/cyphfell/${localPath}`;
37 | }
38 |
39 | /**
40 | * Finds the absolute path to the imported file
41 | * @param {String} currentPath - the absolute path to the file importing another file
42 | * @param {String} importPath - importPath - the path a file is being imported from
43 | * @return {String} - the absolute path to the file being imported
44 | */
45 | static findAbsolutePathToImport(currentPath, importPath) {
46 | let path = this.findPathWithExtension(url.resolve(currentPath, importPath));
47 | if (fs.existsSync(path)) {
48 | return path.replace("//", "/");
49 | }
50 | const testExistence = (resolver, pathTest) => {
51 | if (resolver.includes("node_modules")) {
52 | const newPath = options.replaceModuleImport(pathTest);
53 | if (newPath) {
54 | return newPath.replace("//", "/");
55 | }
56 | }
57 | return pathTest.replace("//", "/");
58 | };
59 |
60 | // TODO: tests for aliasing
61 | for (const resolver of options.moduleResolvePaths) {
62 | path = this.findPathWithExtension(url.resolve(resolver + "/", importPath));
63 | if (fs.existsSync(path)) {
64 | return testExistence(resolver, path);
65 | } else {
66 | for (const alias of options.moduleAliases) {
67 | const aliasedPath = this.findPathWithExtension(url.resolve(resolver + "/", importPath.replace(alias.alias, alias.actual)));
68 | if (importPath.startsWith(alias.alias) && fs.existsSync(aliasedPath)) {
69 | return testExistence(resolver, aliasedPath);
70 | }
71 | }
72 | }
73 | }
74 |
75 | if (!importPath.endsWith(".js") && !importPath.endsWith(".json")) {
76 | importPath = `${importPath}.js`;
77 | }
78 | return url.resolve(currentPath, importPath);
79 | }
80 | }
81 |
82 | module.exports = FilePathUtil;
--------------------------------------------------------------------------------
/packages/cyphfell/src/converters/wdio/WDIOStrategy.js:
--------------------------------------------------------------------------------
1 | const BaseStrategy = require("../BaseStrategy");
2 | const wdioReplacements = require("./WDIORegexReplacements");
3 | const baseTransformedReturns = require("../../regex/ReverseReturnRegex");
4 | const temp = require("./TemporaryRegexReplacements");
5 | const fpUtil = require("../../util/FilePathUtil");
6 | const name = require("../../constants/FrameworkConstants").WebdriverIO;
7 |
8 | class WDIOStrategy extends BaseStrategy {
9 |
10 | /**
11 | * Gets a list of all regular expressions to replace, and what to replace them with
12 | * @return {Array