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

Tests don't run on Windows without admin privileges #7390

Closed
7 tasks done
j-maas opened this issue Mar 20, 2022 · 6 comments · Fixed by #7465
Closed
7 tasks done

Tests don't run on Windows without admin privileges #7390

j-maas opened this issue Mar 20, 2022 · 6 comments · Fixed by #7465
Labels
documentation Improvements or additions to documentation pending triage windows only

Comments

@j-maas
Copy link
Contributor

j-maas commented Mar 20, 2022

Describe the bug

When I try to run the tests, I get a crash because a symlink cannot be created.

$ pnpm run test

> vite-monorepo@ test C:\Users\Johannes\Code\vite
> run-s test-serve test-build


> vite-monorepo@ test-serve C:\Users\Johannes\Code\vite     
> jest

Error: Jest: Got error running globalSetup - C:\Users\Johannes\Code\vite\scripts\jestGlobalSetup.cjs, reason: EPERM: operation not permitted, symlink 'C:\Users\Johannes\Code\vite\packages\plugin-vue-jsx' -> 'C:\Users\Johannes\Code\vite\packages\temp\worker\node_modules\@vitejs\plugin-vue-jsx'       
 ELIFECYCLE  Command failed with exit code 1.
ERROR: "test-serve" exited with 1.
 ELIFECYCLE  Test failed. See above for more details.

I can get around this by opening VSCode with admin privileges (in the startup menu, search for "VSCode", right-click, and run as admin). Some of the tests do still fail, but it's only 4 out of 465.1

It is possible that I have not set up my development environment correctly. I'm running Git Bash (MINGW64) in VSCode as my terminal, but I get the same error in Cmd (if I run Cmd as an admin, it works).

Reproduction

https://github.com/vitejs/vite

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
    Memory: 9.60 GB / 15.97 GB
  Binaries:
    Node: 14.15.5 - C:\Program Files\nodejs\node.EXE  
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD    
    npm: 8.1.4 - C:\Program Files\nodejs\npm.CMD      
  Browsers:
    Chrome: 99.0.4844.74
    Edge: Spartan (44.19041.1266.0), Chromium (99.0.1150.46)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vite: workspace:* => 2.9.0-beta.4

Used Package Manager

pnpm

Logs

No response

Validations

Footnotes

  1. Failed tests:

     FAIL  packages/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts (46.281 s)
      ● /
    
        thrown: "Exceeded timeout of 30000 ms for a hook. 
        Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
    
          57 | }
          58 |
        > 59 | beforeAll(async () => {
             | ^
          60 |   const page = global.page
          61 |   if (!page) {
          62 |     return
    
          at Object.<anonymous> (scripts/jestPerTestSetup.ts:59:1)
    
    
      ● Test suite failed to run
    
        listen EADDRINUSE: address already in use :::9528 
    
          32 |   return new Promise((resolve, reject) => {      33 |     try {
        > 34 |       const server = app.listen(port, () => {
             |                          ^
          35 |         resolve({
          36 |           // for test teardown
          37 |           async close() {
    
          at packages/playground/ssr-webworker/__tests__/serve.js:34:26
          at serve (packages/playground/ssr-webworker/__tests__/serve.js:32:10)
          at scripts/jestPerTestSetup.ts:88:20
    
     FAIL  packages/playground/ssr-pug/__tests__/ssr-pug.spec.ts (31.084 s)
      ● injected inline scripts › no injected inline scripts are present
    
        thrown: "Exceeded timeout of 30000 ms for a hook.
        Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
    
          57 | }
          58 |
        > 59 | beforeAll(async () => {
             | ^
          60 |   const page = global.page
          61 |   if (!page) {
          62 |     return
    
          at Object.<anonymous> (scripts/jestPerTestSetup.ts:59:1)
    
      ● injected inline scripts › injected script proxied 
    correctly
    
        thrown: "Exceeded timeout of 30000 ms for a hook.
        Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
    
          57 | }
          58 |
        > 59 | beforeAll(async () => {
             | ^
          60 |   const page = global.page
          61 |   if (!page) {
          62 |     return
    
          at Object.<anonymous> (scripts/jestPerTestSetup.ts:59:1)
    
    
      ● Test suite failed to run
    
        listen EADDRINUSE: address already in use :::9530 
    
          17 |   return new Promise((resolve, reject) => {      18 |     try {
        > 19 |       const server = app.listen(port, () => {
             |                          ^
          20 |         resolve({
          21 |           // for test teardown
          22 |           async close() {
    
          at Function.listen (node_modules/.pnpm/express@4.17.2/node_modules/express/lib/application.js:618:24)
          at packages/playground/ssr-pug/__tests__/serve.js:19:26
          at serve (packages/playground/ssr-pug/__tests__/serve.js:17:10)
          at scripts/jestPerTestSetup.ts:88:20
    
    
    Test Suites: 3 failed, 61 passed, 64 total
    Tests:       4 failed, 461 passed, 465 total
    Snapshots:   61 passed, 61 total
    Time:        74.32 s
    Ran all test suites.
    ELIFECYCLE  Command failed with exit code 1.
    ERROR: "test-serve" exited with 1.
    ELIFECYCLE  Test failed. See above for more details.
    
@sapphi-red
Copy link
Member

This is caused because fs-extra.copy copies junctions as symlinks. It was not implemented because there is not a function to detect a junction in fs.
jprichardson/node-fs-extra#626
jprichardson/node-fs-extra#726
nodejs/help#1520
libuv/libuv#2384

@bluwy
Copy link
Member

bluwy commented Mar 25, 2022

Thanks for the links @sapphi-red. Do you think this is fixable on Vite's end, or should we document this edge case for Windows?

@sapphi-red
Copy link
Member

I think it is not fixable.
But it maybe helpful for windows users to mention about this in the document.

It seems if you turn on developer mode, it allows you to create symlinks without being an admin.
It worked for me too. (I was always running scripts in admin among this situation...)

Now in Windows 10 Creators Update, a user (with admin rights) can first enable Developer Mode, and then any user on the machine can run the mklink command without elevating a command-line console.
https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/

@bluwy bluwy added the documentation Improvements or additions to documentation label Mar 26, 2022
@j-maas
Copy link
Contributor Author

j-maas commented Mar 26, 2022

I can confirm that activating Developer Mode fixed the issue for me. Thanks for sharing this tip!

Is it feasible to detect this issue when running the tests and providing guidance and a link to the Windows documentation when it happens? If you could give me some hints for where to start looking, I might have a go at that.

In the meantime, I can open a PR that adds a notice to the documentation.

@sapphi-red
Copy link
Member

If you could give me some hints for where to start looking, I might have a go at that.

The error is happening here, so I think it is possible to catch it here.

await fs.copy(path.resolve(__dirname, '../packages/playground'), tempDir, {

@j-maas
Copy link
Contributor Author

j-maas commented Mar 26, 2022

@sapphi-red Thanks a lot for the pointer to the code! It was surprisingly easy with your help.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation pending triage windows only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants