bcoe / c8

output coverage reports using Node.js' built in coverage
ISC License
2k stars 91 forks source link

Coverage shows 0% in windows 11 but works good in WSL2 #491

Open chouzz opened 1 year ago

chouzz commented 1 year ago

Reproduce steps:

  1. Generate vscode sample extension

    npm install -g yo generator-code
    yo code 
    // input extension-test and other can be default
  2. Install c8, according to https://stackoverflow.com/questions/71664061/how-to-generate-a-coverage-report-with-vscode-extension-tests

  3. Make a sample test case: Make new file in src called resolvedPath.ts

    import * as path from 'path';
    
    export function createResolvedFilePath(...pathParts: string[]) {
      return path.resolve(...pathParts);
    }

    make test file in test/suite/resolvedPath.test.ts

    import * as assert from 'assert';
    import { createResolvedFilePath } from '../../resolvedPath';
    
    suite('Suite::Tests::ResolvedPath', async () => {
      test('Test::should return full path', async () => {
          const resolvedPath = createResolvedFilePath('/home/user/src/main.cpp');
          assert.strictEqual(resolvedPath, '/home/user/src/main.cpp');
      });
    
    });
    

    And use this function in extension.ts

    export function activate(context: vscode.ExtensionContext) {
    
      // Use the console to output diagnostic information (console.log) and errors (console.error)
      // This line of code will only be executed once when your extension is activated
      console.log('Congratulations, your extension "extension-test" is now active!');
      // add test function
      const resolvedPath = createResolvedFilePath(
          process.platform === 'win32' ? 'd:/' : '/', 'user', 'src');
      console.log(resolvedPath)
      // The command has been defined in the package.json file
      // Now provide the implementation of the command with registerCommand
      // The commandId parameter must match the command field in package.json
      let disposable = vscode.commands.registerCommand('extension-test.helloWorld', () => {
          // The code you place here will be executed every time your command is executed
          // Display a message box to the user
          vscode.window.showInformationMessage('Hello World from extension-test!');
      });
    
      context.subscriptions.push(disposable);
    }
  4. run coverage command

    npm run coverage

In wsl, it works good:

    ✔ Sample test
  Suite::Tests::ResolvedPath
    ✔ Test::should return full path
  2 passing (9ms)
[23786:0811/113714.110698:ERROR:cert_verify_proc_builtin.cc(670)] CertVerifyProcBuiltin for marketplace.visualstudio.com failed:
----- Certificate i=1 (CN=Huawei Web Secure Internet Gateway CA,OU=IT,O=Huawei,L=Shenzhen,ST=GuangDong,C=cn) -----
ERROR: No matching issuer found

[23853:0811/113714.111671:ERROR:ssl_client_socket_impl.cc(982)] handshake failed; returned -1, SSL error code 1, net_error -202
XHR failed: Error: XHR failed
    at y.onerror (vscode-file://vscode-app/home/xxxxx/src/extension-test/.vscode-test/vscode-linux-x64-1.81.1/resources/app/out/vs/workbench/workbench.desktop.main.js:77:1261)
[main 2023-08-11T03:37:14.116Z] Extension host with pid 24137 exited with code: 0, signal: unknown.
Exit code:   0
Done

-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |   14.28 |       50 |      50 |   14.28 |
 extension.ts    |       0 |        0 |       0 |       0 | 1-30
 resolvedPath.ts |     100 |      100 |     100 |     100 |
-----------------|---------|----------|---------|---------|-------------------
ERROR: Coverage for lines (14.28%) does not meet global threshold (90%)

image

But in windows 11, it doesn't work:

PS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
Found existing install in D:\src\samples\typescript\extension-test\.vscode-test\vscode-win32-x64-archive-1.81.1. Skipping download

[main 2023-08-11T03:49:09.234Z] update#setState disabled
[main 2023-08-11T03:49:09.237Z] update#ctor - updates are disabled by the environment
Loading development extension at d:\src\samples\typescript\extension-test
[vscode.php]: One or more snippets from the extension 'php' very likely confuse snippet-variables and snippet-placeholders (see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax for more details)

  Extension Test Suite
    √ Sample test
  Suite::Tests::ResolvedPath
    √ Test::should return full path
  2 passing (4ms)
[main 2023-08-11T03:49:11.484Z] Extension host with pid 48856 exited with code: 0, signal: unknown.
Exit code:   0
Done

-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |       0 |        0 |       0 |       0 |
 extension.ts    |       0 |        0 |       0 |       0 | 1-29
 resolvedPath.ts |       0 |        0 |       0 |       0 | 1-5
-----------------|---------|----------|---------|---------|-------------------
ERROR: Coverage for lines (0%) does not meet global threshold (90%)

image

chouzz commented 1 year ago

Update:

c8 v6.0.1 works good in windows, but v7 and v8 not ok.