Snapshot testing

For snapshot testing we do not have to explicitly write the output (the snapshot). Snapshots are created when the tests are run for the first time, and updated utilizing an update command. The test succeeds if the current snapshot is the same as the last accepted snapshot. By checking the test output, or updating and analyzing the test differences, the developer can know whether a change was expected or not.

Testing syntax highlighting

VS code uses TexMate grammars as its tokenization engine, see syntax-highlight guide. The grammar is loaded via a JSON file that uses the oniguruma dialect.

To test we utilize the third party vscode-tmgrammar-test library. The input file's path and extension are set in package.json, and the snapshots are saved in the same directory as the inputs. The snapshot filename is equal to the complete filename of the input (including the extension) with ‘.snap’ attached at its end.

Commands

  • Test everything: npm run test
  • Update snapshot: npm run update-syntax-snapshot