fix: issue while running typescript files#3316
fix: issue while running typescript files#3316beatfactor merged 25 commits intonightwatchjs:mainfrom
Conversation
beatfactor
left a comment
There was a problem hiding this comment.
Remove ts-node as a main dependency. See also #3312 (comment)
|
@vaibhavsingh97 any updates here? |
| Nightwatch.cli(function(argv) { | ||
| Nightwatch.cli(function (argv) { | ||
| const projectTsFilePath = findTSConfigFile(); | ||
| if (projectTsFilePath !== '') { |
There was a problem hiding this comment.
I actually missed this before, but we also need to check for the disable_typescript setting, which might mean that we need to move all this into the CLIRunner class after we parse the settings.
| const projectTsFileLocation2 = path.join(process.cwd(), 'tsconfig.nightwatch.json'); | ||
| if (Utils.fileExistsSync(projectTsFileLocation1)) { | ||
| return projectTsFileLocation1; | ||
| } else if (Utils.fileExistsSync(projectTsFileLocation2)) { |
| project: projectTsFile | ||
| }); | ||
| } catch (err) { | ||
| Logger.error(err); |
There was a problem hiding this comment.
here we can check if ts-node has been installed in the current project and if not, display the appropriate error message.
| static findTSConfigFile() { | ||
| const projectTsFileLocation1 = path.join(process.cwd(), 'nightwatch', 'tsconfig.json'); | ||
| const projectTsFileLocation2 = path.join(process.cwd(), 'tsconfig.nightwatch.json'); | ||
| if (Utils.fileExistsSync(projectTsFileLocation1)) { |
There was a problem hiding this comment.
We can actually add a new setting called tsconfig_path (empty by default) so users can set that to whatever they want, in which case they can re-use the existing tsconfig file if they want to. If this property is set, then it should take precedence.
There was a problem hiding this comment.
@vaibhavsingh97 any progress with adding the tsconfig_path setting?
| static findTSConfigFile() { | ||
| const projectTsFileLocation1 = path.join(process.cwd(), 'nightwatch', 'tsconfig.json'); | ||
| const projectTsFileLocation2 = path.join(process.cwd(), 'tsconfig.nightwatch.json'); | ||
| if (Utils.fileExistsSync(projectTsFileLocation1)) { | ||
| return projectTsFileLocation1; | ||
| } else if (Utils.fileExistsSync(projectTsFileLocation2)) { | ||
| return projectTsFileLocation2; | ||
| } | ||
|
|
||
| return ''; | ||
| } |
There was a problem hiding this comment.
| static findTSConfigFile() { | |
| const projectTsFileLocation1 = path.join(process.cwd(), 'nightwatch', 'tsconfig.json'); | |
| const projectTsFileLocation2 = path.join(process.cwd(), 'tsconfig.nightwatch.json'); | |
| if (Utils.fileExistsSync(projectTsFileLocation1)) { | |
| return projectTsFileLocation1; | |
| } else if (Utils.fileExistsSync(projectTsFileLocation2)) { | |
| return projectTsFileLocation2; | |
| } | |
| return ''; | |
| } | |
| static findTSConfigFile() { | |
| const allowedFileLocation = [ | |
| path.join('nightwatch', 'tsconfig.json'), | |
| 'tsconfig.nightwatch.json' | |
| ]; | |
| const filesPresent = allowedFileLocation | |
| .map((fileLocation) => path.join(process.cwd(), fileLocation)) | |
| .filter((filePath) => Utils.fileExistsSync(filePath)); | |
| return filesPresent[0] || ''; | |
| } |
There was a problem hiding this comment.
I am in favour of the existing implementation which is a bit simpler and easier to understand. Besides, .filter() will search the whole array even if the first file is found. We should use Array.some() instead.
| const projectTsFilePath = findTSConfigFile(); | ||
| if (projectTsFilePath !== '') { | ||
| loadTSNode(projectTsFilePath); | ||
| } |
There was a problem hiding this comment.
| const projectTsFilePath = findTSConfigFile(); | |
| if (projectTsFilePath !== '') { | |
| loadTSNode(projectTsFilePath); | |
| } | |
| const isTypescriptProject = Utils.fileExistsSync(path.join(process.cwd(), 'tsconfig.json'); | |
| if (isTypescriptProject) { | |
| const projectTsFilePath = findTSConfigFile(); | |
| if (projectTsFilePath !== '') { | |
| loadTSNode(projectTsFilePath); | |
| } else { | |
| console.log('You can now run TS tests directly using Nightwatch.\nFollow this doc to learn more.'); | |
| } | |
| } |
^ This will also help in cases where a user has mistakenly deleted the nightwatch/tsconfig.json file and is now trying to run ts test file but is unable to do so (because we are not loading ts-node anymore).
| } | ||
|
|
||
| static get CONFIG_FILE_TS() { | ||
| return './nightwatch.conf.ts'; |
There was a problem hiding this comment.
@vaibhavsingh97 we need a test that checks for this.
| return path.resolve(CliRunner.CONFIG_FILE_CJS); | ||
| } | ||
| // TODO: check for both the `nightwatch/tsconfig.json` and `tsconfig.nightwatch.json` | ||
| if (Utils.fileExistsSync(path.resolve('tsconfig.nightwatch.json'))) { |
There was a problem hiding this comment.
should be refactored into a usingTS constant, similarly to the usingESM one above and I think we should also check if CliRunner.CONFIG_FILE_TS exists, because you can use a .js or .json config file even if you are using TS.
@garg3133 do we create the nightwatch.conf.ts from the init tool?
| throw new Error('Does not exist'); | ||
| } | ||
|
|
||
| if (module === './nightwatch.conf.ts'){ |
There was a problem hiding this comment.
the failures on windows are because of this.
| loadTypescriptTranspiler() { | ||
| const isTypescriptProject = Utils.fileExistsSync(path.join(process.cwd(), 'tsconfig.json')); | ||
| if (isTypescriptProject) { | ||
| Logger.info('Now you can run TS tests directly using Nightwatch.\nFollow this document to learn more.'); |
There was a problem hiding this comment.
@vishalshah133 Need to work on it, I had removed the line for now
|
What is the new way to extend/override built in types to add properties that would normally be added to the browser (for example custom_commands |
Fixes: #3312
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.
features/my-new-featureorissue/123-my-bugfix);