Add tools and scripts for writing and running javascript unit tests

Created on 8 October 2016, about 8 years ago
Updated 15 February 2023, almost 2 years ago

At this point we assume core is using ES6, following Airbnb coding standards.

There are hundred of testing libraries. One of the most used testing tool is mocha (also used by airbnb). But it doesn't really matter, most testing libs are the same. This one has integration written for (almost?) everything we can think of using in core js.

The patch is big since it's a diff from my es6 branch. I split the test code in it's own patch for showing how it looks like. For now apply the huge patch and run the following

npm install
npm run test:core

This is the output (with code coverage):

$ npm run test:core

> Drupal@8.3.0 test:core …/drupal
> nyc mocha -r jsdom-global/register $(find core/ -name '*.test.js') || exit 0



  Drupal
    #checkPlain()
      βœ“ should escape html strings safe for printing


  1 passing (6ms)

---------------|----------|----------|----------|----------|----------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
---------------|----------|----------|----------|----------|----------------|
All files      |    19.44 |     1.54 |    11.11 |       20 |                |
 drupal.es6.js |    19.44 |     1.54 |    11.11 |       20 |... 573,574,588 |
---------------|----------|----------|----------|----------|----------------|

There are many things to fix, like mocking the browser env, fixing scripts so that mocking isn't needed, excluding vendor code from code coverage, a way to compile es6 files on the fly for testing, etc.

But it's a start.

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
JavascriptΒ  β†’

Last updated 3 days ago

Created by

πŸ‡«πŸ‡·France nod_ Lille

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024