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

transpile ts to js to handle ts types #4133

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ansh21
Copy link

@ansh21 ansh21 commented Mar 19, 2024

Thanks in advance for your contribution. Please follow the below steps in submitting a pull request, as it will help us with reviewing it quicker.

  • Before marking your PR for review, please test and verify your changes by making appropriate modifications to any of the Nightwatch example tests (present in examples/tests directory of the project) and running them. ecosia.js and duckDuckGo.js are good examples to work with.
  • Create a new branch from master (e.g. features/my-new-feature or issue/123-my-bugfix);
  • If you're fixing a bug also create an issue if one doesn't exist yet;
  • If it's a new feature explain why do you think it's necessary. Please check with the maintainers beforehand to make sure it is something that we will accept. Usually we only accept new features if we feel that they will benefit the entire community;
  • Please avoid sending PRs which contain drastic or low level changes. If you are certain that the changes are needed, please discuss them beforehand and indicate what the impact will be;
  • If your change is based on existing functionality please consider refactoring first. Pull requests that duplicate code will most likely be ignored;
  • Do not include changes that are not related to the issue at hand;
  • Follow the same coding style with regards to spaces, semicolons, variable naming etc.;
  • Always add unit tests - PRs without tests are most of the times ignored.

Fixes #3688

Dev Testing Steps:
Test case 1:

  • renamed nightwatch.conf.js to nightwatch.conf.ts . Tried adding few types to the ts file.
  • Executed node ./bin/nightwatch examples/tests/ecosia.js --env chrome to check if the test was successful

Test case 2:

  • tested with the nightwatch.conf.js itself to ensure the current functionalities are not broken.

@CLAassistant
Copy link

CLAassistant commented Mar 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

Status

  • ❌ No modified files found in the types directory.
    Please make sure to include types for any changes you have made. Thank you!.

@AutomatedTester
Copy link
Member

The PR title and commit don't seem related. Could you update this please

@ansh21 ansh21 changed the title lint fix transpile ts to js to handle ts types Mar 22, 2024
@ansh21
Copy link
Author

ansh21 commented Mar 22, 2024

The PR title and commit don't seem related. Could you update this please

Addressed

Copy link
Member

@garg3133 garg3133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need to make sure that in case user has a ts config files with name nightwatch-ts.conf.js (which is a non-default name) and we pass the name of the config using the --config flag while running tests, it is able to transpile this config as well.

Right now, it won't work because in case a --config flag is provided, the flow will go to the else block (which contains the code this.argv.config = path.resolve(this.argv.config);) and there we do not have any way to transpile the ts file.

};
const transpiledCode = ts.transpileModule(tsFileContent, {compilerOptions});
const jsCode = transpiledCode.outputText;
var Module = module.constructor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, we can also put a const Module = require('module'); statement at the top of the function definition (where other requires are done).

const transpiledCode = ts.transpileModule(tsFileContent, {compilerOptions});
const jsCode = transpiledCode.outputText;
var Module = module.constructor;
var m = new Module();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use const instead of var for declaring variables. Also, we should define proper variable names, module would be a better name instead of m here.

@@ -354,7 +372,11 @@ class CliRunner {
newConfigCreated = CliRunner.createDefaultConfig(localJsOrTsValue);
}

if (hasJsOrTsConfig || newConfigCreated) {
if (Utils.fileExistsSync(CliRunner.CONFIG_FILE_TS)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ideally use localJsOrTsValue here as our source of truth to decide if the ts config file is our primary config for the project. This is because the logic used to find localJsOrTsValue may change later and we may give preference to some other config file even if a nightwatch.conf.ts file is present.

This could be solved by changing this statement to:
localJsOrTsValue.includes(path.basename(CliRunner.CONFIG_FILE_TS))

And for the issue you were facing with tests, that could be solved by changing the basename definition in mockery to:

    basename(a) {
        if (a === './globals.json') {
          return 'globals';
        }

        return origPath.basename(a);
      },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

config and globals files with types do not allow nightwatch to run tests
4 participants