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

Run unit tests inside browsers #90063

Closed
jrieken opened this issue Feb 5, 2020 · 19 comments
Closed

Run unit tests inside browsers #90063

jrieken opened this issue Feb 5, 2020 · 19 comments
Assignees
Labels
engineering VS Code - Build / issue tracking / etc.
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Feb 5, 2020

With #90010 we have the ability to run unit tests inside browsers, using playwright. To run them use this command

> node test/browser/index.js

Use the --run <glob>-option to narrow select tests by file path and and use the --browser <webkit|chromium|firefox>-option to select the target runtime (note that firefox currently doesn't work, microsoft/playwright#842).

The plan is to make this part of our build but first we need to fix some test failures that seems to only fail in (some) browser types:

These test fail running inside browsers (chromium or webkit, node test/browser/index.js --browser chromium) @isidorn

  1) Debug - ANSI Handling Expected single sequence operation - /CHROMIUM/:
  2) Debug - ANSI Handling Expected single 8-bit color sequence operation - /CHROMIUM/:
  3) Debug - ANSI Handling Expected multiple sequence operation - /CHROMIUM/:

These test fail only when running node test/browser/index.js --browser webkit @alexdima

  1) MinimapCharRenderer letter d @ 2x - /WEBKIT/:
  2) Decoration Render Options css properties - /WEBKIT/:
  3) Decoration Render Options css properties, gutterIconPaths - /WEBKIT/:
  4) chunk based search #45770. FindInNode should not cross node boundary. - /WEBKIT/:
  5) FindController query options persistence wholeWord - /WEBKIT/:
  6) FindModel incremental find from beginning of file - /WEBKIT/:
  7) FindModel find model next - /WEBKIT/:
  8) FindModel find model next stays in scope - /WEBKIT/:
  9) FindModel find model prev - /WEBKIT/:
  10) FindModel find model prev stays in scope - /WEBKIT/:
  11) FindModel find model next/prev respects cursor position - /WEBKIT/:
  12) FindModel replace hello - /WEBKIT/:
  13) FindModel replaceAll hello - /WEBKIT/:
  14) FindModel listens to model content changes - /WEBKIT/:
  15) FindModel selectAllMatches - /WEBKIT/:
  16) FindModel issue #14143 selectAllMatches should maintain primary cursor if feasible - /WEBKIT/:
  17) FindModel issue #18711 replaceAll with empty string - /WEBKIT/:
  18) FindModel issue #27083. search scope works even if it is a single line - /WEBKIT/:
  19) Multicursor selection AddSelectionToNextFindMatchAction starting with single collapsed selection - /WEBKIT/:
  20) Multicursor selection Find state disassociation enters mode - /WEBKIT/:
  21) Multicursor selection Find state disassociation leaves mode when selection changes - /WEBKIT/:
  22) Multicursor selection Find state disassociation Select Highlights respects mode  - /WEBKIT/:
@jrieken jrieken added the engineering VS Code - Build / issue tracking / etc. label Feb 5, 2020
@isidorn
Copy link
Contributor

isidorn commented Feb 5, 2020

Those ansii tests were written as part of a PR. I do not have a good idea why they fail inside Chromium and work when run in VS Code. I tried debugging them with --debug but failed.
To unblock you I can move the tests under electron-browser.

@jrieken
Copy link
Member Author

jrieken commented Feb 5, 2020

@isidorn this is all new but with --debug --browser chromium you should see a browser in which you should be able to use devtools

@isidorn
Copy link
Contributor

isidorn commented Feb 5, 2020

@jrieken yes I tried that and I do see chromium, but none of the tests get rendered and the window closes before I can do anything (put a breakpoint).

@jrieken
Copy link
Member Author

jrieken commented Feb 5, 2020

Yes. In the renderer the tests run without mocha UX. What you can try is this: start with --debug, open dev tools, select "pause on script exec", wait for the pause and set breakpoints that you want/need

@isidorn
Copy link
Contributor

isidorn commented Feb 5, 2020

Yeah that works, just not very convenient as you have to be fast. Thanks!

@jrieken
Copy link
Member Author

jrieken commented Feb 5, 2020

FYI - you can now debug tests by simply opening the test/browser/renderer.html page in a browser. Use a uri like this, notice the m-query arguments (this is AMD module ids):

file:///Users/jrieken/Code/vscode/test/browser/renderer.html?m=vs/editor/test/browser/services/decorationRenderOptions.test&m=vs/editor/test/browser/services/decorationRenderOptions.test

In the presence of test failures, the runner will also make an attempt to print the right link for you. 👇

Screenshot 2020-02-05 at 15 48 37

alexdima added a commit that referenced this issue Feb 5, 2020
@jrieken jrieken added this to the February 2020 milestone Feb 5, 2020
@alexdima
Copy link
Member

alexdima commented Feb 5, 2020

Actually it appears that there are still failures on Windows:

 1) Paths (Node Implementation) dirname - /CHROMIUM/:
     ReferenceError: __filename is not defined
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/path.test.js:146:60)

  2) Paths (Node Implementation) extname - /CHROMIUM/:
     ReferenceError: __filename is not defined
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/path.test.js:219:18)

  3) Paths (Node Implementation) resolve - /CHROMIUM/:

      AssertionError:
path.win32.resolve(".")
  expect="/"
  actual="\\"
      + expected - actual

      -1
      +0

      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/path.test.js:369:20)

  4) Paths (Node Implementation) basename - /CHROMIUM/:
     ReferenceError: __filename is not defined
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/path.test.js:382:46)

  5) Resources relativePath - /CHROMIUM/:

      AssertionError: from file://server/share/some/ to file://server/share2/some/path
      + expected - actual

      -/share2/some/path
      +../../share2/some/path

      at assertRelativePath (file:///C:/Alex/src/vscode/out/vs/base/test/common/resources.test.js:210:20)
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/resources.test.js:245:17)

  6) Debug - ANSI Handling Expected single sequence operation - /CHROMIUM/:

      AssertionError: Custom foreground class not found on element after foreground ANSI code #30.
      + expected - actual

      -false
      +true

      at file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:135:21
      at assertSingleSequenceElement (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:83:13)
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:134:17)

  7) Debug - ANSI Handling Expected single 8-bit color sequence operation - /CHROMIUM/:

      AssertionError: Custom color class not found after foreground 8-bit color code 38;5;0
      + expected - actual

      -false
      +true

      at file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:193:21
      at assertSingleSequenceElement (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:83:13)
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:192:17)

  8) Debug - ANSI Handling Expected multiple sequence operation - /CHROMIUM/:

      AssertionError: Foreground color class not found after multiple different ANSI codes.
      + expected - actual

      -false
      +true

      at file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:288:17
      at assertSingleSequenceElement (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:83:13)
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/workbench/contrib/debug/test/browser/debugANSIHandling.test.js:284:13)

@alexdima alexdima reopened this Feb 5, 2020
@jrieken
Copy link
Member Author

jrieken commented Feb 5, 2020

The tests for path have been moved to the node-layer. @alexdima I believe that you are missing a fresh compile

@alexdima
Copy link
Member

alexdima commented Feb 5, 2020

@jrieken You're right. But after restarting gulp watch I see one test failure left:

  1) Resources relativePath - /CHROMIUM/:

      AssertionError: from file://server/share/some/ to file://server/share2/some/path
      + expected - actual

      -/share2/some/path
      +../../share2/some/path

      at assertRelativePath (file:///C:/Alex/src/vscode/out/vs/base/test/common/resources.test.js:210:20)
      at Context.<anonymous> (file:///C:/Alex/src/vscode/out/vs/base/test/common/resources.test.js:245:17)

@jrieken
Copy link
Member Author

jrieken commented Feb 6, 2020

@aeschli can you take a look at those ☝️ test failures

@aeschli
Copy link
Contributor

aeschli commented Feb 6, 2020

Running node test/browser/index.js --browser webkit on Ubuntu with Chromium I only get the following test failure:
(HEAD ea8d1b7)

1) MinimapCharRenderer letter d @ 2x - /WEBKIT/:

      [46,46,46,255,173,173,173,255,198,198,198,255,202,202,202,255,193,193,193,255,204,204,204,255,0,0,0,255,0,0,0,255] deepEqual [46,46,46,255,173,173,173,255,198,198,198,255,200,200,200,255,193,193,193,255,204,204,204,255,0,0,0,255,0,0,0,255]
      + expected - actual

         198
         198
         198
         255
      -  202
      -  202
      -  202
      +  200
      +  200
      +  200
         255
         193
         193
         193

@jrieken
Copy link
Member Author

jrieken commented Feb 6, 2020

@aeschli yes - this is Chromium and windows

@aeschli
Copy link
Contributor

aeschli commented Feb 6, 2020

I fixed the relativePath test failure

@jrieken
Copy link
Member Author

jrieken commented Feb 7, 2020

@jrieken jrieken assigned alexdima and unassigned aeschli Feb 7, 2020
@bpasero
Copy link
Member

bpasero commented Feb 7, 2020

@jrieken maybe something to consider: we support yarn smoketest --web --browser <type> for smoke tests. We could add a script like that for unit tests as well?

@jrieken
Copy link
Member Author

jrieken commented Feb 7, 2020

With the PR above there is yarn test-browser

@alexdima
Copy link
Member

alexdima commented Feb 7, 2020

@jrieken Could we make this one compatible with the other one, i.e.

node test\unit\browser\index.js --browser webkit --run src/vs/editor/test/browser/services/decorationRenderOptions.test.ts

does not work while it works in the other one, e.g.

scripts\test.bat --run src/vs/editor/test/browser/services/decorationRenderOptions.test.ts

This is superhelpful for me because I have a copy relative path plugin that I use on files and then I just paste the path

@jrieken
Copy link
Member Author

jrieken commented Feb 7, 2020

The --run argument is now supported as in other tests, there is now --run for workspace relative paths (with TS → JS trickery) and there is --glob for patterns

@jrieken
Copy link
Member Author

jrieken commented Feb 7, 2020

All tests green, PR merged, done

@jrieken jrieken closed this as completed Feb 7, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engineering VS Code - Build / issue tracking / etc.
Projects
None yet
Development

No branches or pull requests

6 participants