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

Ability to disable support for using TypeScript in Version 1.6 #2677

Closed
franklychilled opened this issue Apr 30, 2021 · 5 comments · Fixed by #2696
Closed

Ability to disable support for using TypeScript in Version 1.6 #2677

franklychilled opened this issue Apr 30, 2021 · 5 comments · Fixed by #2696

Comments

@franklychilled
Copy link

franklychilled commented Apr 30, 2021

Is your feature request related to a problem? Please describe.
Our test suites are written in Typescript since 2018 and we are not able to upgrade from version 1.5.1 to 1.6.3. We are using type definition and base classes.

Describe the solution you'd like
Addition attribute available in nightwatch.json

Describe how the solution will work
Stop loading any *.ts files anywhere.

Describe alternatives you've considered
Ignore .ts files if a .js file exists anywhere (Custom Assertions, tests, etc...)

Additional context
We have are maintaining 2 larges test suites and we would appreciate a solution which doesn't requires a complete rewrite of our test suite.

Linked to:
1.6.0 - Added #2559 – support for using TypeScript (.ts) for test files
1.6.3 - Fixed #2627 - an issue with custom commands written in Typescript

Interim solution is to tweak the latest source code with

# fix to stop loading ts files in nightwatch
filename="node_modules/nightwatch/lib/utils/index.js"
search="return '.ts';"
replace="return '._ts';"
sed -i "s/$search/$replace/" $filename
@franklychilled
Copy link
Author

Note: when I replace '.ts' but '.js', our custom command would not load (due to the code from #2627) so I've switch to '._ts' as we don't have any extension like this.

@Dharin-shah
Copy link
Contributor

Dharin-shah commented May 5, 2021

hey @franklychilled, i have tried having a ts and js file with same name in my custom commands and this function
doesnt allow the ts file to load, am i missing something from the issue you have described

@franklychilled
Copy link
Author

franklychilled commented May 5, 2021

Hi @Dharin-shah,
Yes, you are prevented due to the fix in 1.6.3 - #2627 - an issue with custom commands written in Typescript

I've change this line to return '._ts'; to stop any Typescript file to load.

Our issue is not only about custom commands, we have custom assertions and test in Typescript. We are also using @types/nightwatch@0.9.12 to provide type definition on our test.

Here an example our our Login page test in Typescript

import { NightwatchBrowser } from 'nightwatch';
import { LoginPage } from '../../pages/login/loginPage';
import { CaseType } from '../../pages/caseLoading';

module.exports = {
  'login/login - username, password and memorable word logs in': (browser: NightwatchBrowser) => {
    const login = new LoginPage(browser);

    login.loadCase(CaseType.MyClient)
    login.launch()
         .navigate();

    browser.assert.attributeEquals(login.selectors.btnLogin, 'value', 'Log in', 'Log in button contains the correct text');
         
    login.input().submit();

    summary.waitForLoad();
  },
};

Due to our import statement on top our typescript files, we have errors like

Error: There was an error while trying to load the file xxx.ts: Cannot use import statement outside a module
--
  | at Array.forEach (<anonymous>)
  | at Array.forEach (<anonymous>)

@Dharin-shah
Copy link
Contributor

@franklychilled Interesting, so if i get this correctly, you dont want any .ts files (commands, assertions, tests..) to be loaded in nightwatch since you already generate the js files yourself. Please correct me if I am wrong :)

@franklychilled
Copy link
Author

@Dharin-shah, You are correct, we are compiling all our .ts files using tsc and have already generate the js files. I believe it's a simpler options that supporting the import statement from Typescript.

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

Successfully merging a pull request may close this issue.

3 participants