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

Fix test failures on windows #313

Closed
wants to merge 10 commits into from
Closed

Fix test failures on windows #313

wants to merge 10 commits into from

Conversation

nomuna
Copy link
Contributor

@nomuna nomuna commented Sep 4, 2021

The "npm" executable can not be found on windows. Using "npm.cmd" instead of "npm" fixes the tests.

  • Added two constants for *nix and windows executables and use the fitting one after running an os detection.
  • Tests adjusted to reflect the npm command string change.

Fix #312

The "npm" executable can not be found on windows. Using "npm.cmd" instead of "npm" fixes the tests.

 - Added two constants for *nix and windows executables and use the fitting one after running an os detection.
 - Tests adjusted to reflect the npm command string change.

Fix jhipster#312
@nomuna
Copy link
Contributor Author

nomuna commented Sep 4, 2021

Hey @SudharakaP and @atomfrede,

Could you have a look at this? I wanted to look into the sonar issues of the project but stumbled upon this problem.
Apparently even the pipeline needs approval from a maintainer to run....

Copy link
Member

@SudharakaP SudharakaP left a comment

Choose a reason for hiding this comment

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

Hey @SudharakaP and @atomfrede,

Could you have a look at this? I wanted to look into the sonar issues of the project but stumbled upon this problem.
Apparently even the pipeline needs approval from a maintainer to run....

@nomuna: Firstly, sorry for taking a long time to reply. Somehow I missed this one. Now I took a look but I cannot test this PR as I don't have a Windows machine. On the other hand I am a bit hesitant on trying to support Windows since as far as I know most people in the core team doesn't use Windows and thus we will have a maintainability problem when we try to support Windows commands. One can always use WSL (Windows Subsystem for Linux) instead of trying to run on Windows natively. 🤔

@pascalgrimaud : What is your take on this? 🤔

@@ -62,7 +66,9 @@ public JHipsterService(LogsService logsService, ApplicationProperties applicatio

public void installNpmDependencies(String generationId, File workingDir) throws IOException {
this.logsService.addLog(generationId, "Installing the JHipster version used by the project");
this.runProcess(generationId, workingDir, "npm", "install", "--ignore-scripts", "--package-lock-only");
final String os = System.getProperty("os.name");
final String command = os.contains("indows") ? NPM_WIN : NPM_NIX;
Copy link
Member

Choose a reason for hiding this comment

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

@nomuna : Why is the string "indows" instead of "windows" ? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will still work if it is "Windows" or "windows" :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Besides, this method is only used / called by the test.... Apparently unnecessary even.

For the application to generate a working zip file under windows the jhipster command has to be set to jhipster.cmd
in application-*.yml.

So if the installNpmDependencies method is necessary I would suggest that npm command path is also made configurable through application-*.yml so that the executable path can be set to npm.cmd.

Then the OS detection code can be removed from the method.

@pascalgrimaud
Copy link
Member

I think the project should build and work on Windows, specially if there is few code to update.

Anyway, this PR is not enought, we should rework all path, using File.separator instead of hard coding /x/y/z

So I would say, let do not merge it for now, with the release 7.2.0

@nomuna
Copy link
Contributor Author

nomuna commented Sep 15, 2021

I added this code to my local version to make it work on windows so that I could have a look at the sonar issues. I thought there was a windows pipeline already set up and would trigger on PRs.

- hard coded, os specific path string replaced with os-independent version
  in GeneratorService and GeneratorServiceTest
- removed unused imports in GeneratorServiceTest
@nomuna
Copy link
Contributor Author

nomuna commented Sep 15, 2021

I think the project should build and work on Windows, specially if there is few code to update.

Anyway, this PR is not enought, we should rework all path, using File.separator instead of hard coding /x/y/z

So I would say, let do not merge it for now, with the release 7.2.0

Just pushed a new commit where I replaced all the hard coded / linux paths with OS - independent versions.
Tests are running under windows.

- extended ApplicationProperties for npm process configuration
- the default value for tempDir in ApplicationProperties is the OS spec. temporary folder
- removed OS detection code from JHipsterService
- OS detection and npm path adjustment done to ApplicationProperties before each test
@nomuna nomuna marked this pull request as draft September 15, 2021 13:10
@nomuna nomuna marked this pull request as ready for review September 15, 2021 13:32
@jdubois
Copy link
Member

jdubois commented Nov 11, 2021

I also can't test easily - maybe we could test GitHub Actions with Windows, I need to check as I think that's an option.

Then I think this is important to merge (and many thanks to @nomuna for finding & fixing this!). I had the exact same issue on another project, and as I coded both I probably did the same kind of error with the file separators. So it's all my fault!

@jdubois
Copy link
Member

jdubois commented Aug 25, 2023

Oh this code is also in #316 (also from @nomuna ), so I'm closing this one in favour of the other, more complete PR.

@jdubois jdubois closed this Aug 25, 2023
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.

Tests fail under windows
5 participants