Git Product home page Git Product logo

javascript-test-runner's Introduction

Exercism JavaScript Test Runner

javascript-test-runner / deploy javascript-test-runner / main

The Docker image for automatically run tests on JavaScript solutions submitted to exercism.

At this moment, the input path must be relative to the package.json of this repository. jest doesn't like running outside of its tree. This might change in the future.

Installation

Clone this repository and then run:

yarn install

You'll need at least Node LTS for this to work.

yarn build

Usage

If you're developing this, you can run this via yarn or the provided shell script.

  • .sh enabled systems (UNIX, WSL): yarn execute:dev
  • .bat fallback (cmd.exe, Git Bash for Windows): unsupported

You'll want these :dev variants because it will build the required code (it will transpile from TypeScript to JavaScript, which is necessary to run this in Node environments, unlike Deno environments). When on Windows, if you're using Git Bash for Windows or a similar terminal, the .sh files will work, but will open a new window (which closes after execution). The .bat scripts will work in the same terminal. In this case it might be much easier to run bin/run.sh directly, so a new shell won't open.

You can also manually build using yarn or yarn build, and then run the script directly: ./bin/run.sh arg1 arg2 arg3.

Running the Solution's Tests

To run a solution's tests, do the following:

  1. Open terminal in project's root
  2. Run ./bin/run.sh <exercise-slug> <path-to-solution-folder> [<path-to-output-folder>]

For example:

$ ./bin/run.sh two-fer ./test/fixtures/two-fer/pass

Using reporter : **/dist/reporter.js
Using test-root: **/test/fixtures/two-fer/pass/
Using base-root: **/
Using setup-env: **/dist/jest/setup.js

test/fixtures/two-fer/pass/ matches test/fixtures/two-fer/pass/. Not copying anything.
Using test/fixtures/two-fer/pass/.meta/config.json as base configuration
Enabling tests in test/fixtures/two-fer/pass/two-fer.spec.js
Determining test suites to run...
Find the output at:
test/fixtures/two-fer/pass/results.json

Running the Tests of a Remote Solution

Instead of passing in an <exercises-slug> and <path-to-solution-folder>, you can also directly pass in an https://exercism.io url, as long as you have the exercism CLI installed.

You can pass the following type of URLs:

  • Published solutions: /tracks/javascript/exercises/<slug>/<id>
  • Mentor solutions: /mentor/solutions/<id>
  • Your solutions: /my/solutions/<id>
  • Private solutions: /solutions/<id>

For example:

$ ./bin/run.sh https://exercism.io/my/solutions/a7d1b71693fb4298a3a99bd352dd4d74
Exercism remote UUID: a7d1b71693fb4298a3a99bd352dd4d74

Downloaded to
C:\Users\Derk-Jan\Exercism\javascript\clock

...

Determining test suites to run...
Find the output at:
./tmp/clock/a7d1b71693fb4298a3a99bd352dd4d74/clock/results.json

As you can see, it will be copied to a local directory. It's up to you to clean-up this directory.

Running the Solution's Tests in Docker container

This script is provided for testing purposes

To run a solution's test in the Docker container, do the following:

  1. Open terminal in project's root
  2. Run ./run-in-docker.sh <exercise-slug> <relative-path-to-solution-folder>

Maintaining

The package.json needs to be in-sync with the javascript track package.json.

Testing

Running the tests of the test-runner itself can be achieved by using the test script from package.json. The tests delegate to the build output, which is why yarn test first calls yarn build before running jest. The tests take over a minute to run on a decent machine.

javascript-test-runner's People

Contributors

alirezaghey avatar ccare avatar dependabot[bot] avatar erikschierboom avatar exercism-bot avatar faisalafroz avatar ihid avatar joshgoebel avatar kntsoriano avatar kytrinyx avatar sleeplessbyte avatar tejasbubane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascript-test-runner's Issues

Tests timed out error on a working solution - Mixed Juices / JavaScript

I was trying to complete the Mixed Juices exercise on Javascript track and the solution I came put with seems to be working fine on VScode but when I try running tests on the website I'm getting the YOUR TESTS TIMED OUT error. My solution was:

1. export function timeToMixJuice(name) {
2.     switch(name) {
3.         case 'Pure Strawberry Joy':
4.             return 0.5;
5.         case 'Energizer':
6.             return 1.5;
7.         case 'Green Garden':
8.             return 1.5;
9.         case 'Tropical Island':
10.             return 3;
11.         case 'All or Nothing':
12.             return 5;
13.         default:
14.             return 2.5;
15.     }
16. }
17. 
18. export function limesToCut(wedgesNeeded, limes) {
19.     var wedgesCut = 0; var i = 0;
20.     do {
21.         switch (limes[i]) {
22.             case 'small':
23.                 wedgesCut += 6;
24.                 break;
25.             case 'medium':
26.                 wedgesCut += 8;
27.                 break;
28.             case 'large':
29.                 wedgesCut += 10;
30.                 break;
31.             default:
32.                 break;
33.         }
34.         i++;
35.     } while(wedgesCut < wedgesNeeded);
36.     return i;
37. }
38. 
39. export function remainingOrders(timeLeft, orders) {
40.     do {
41.         timeLeft -= timeToMixJuice(orders[0]);
42.         orders.splice(0,1);
43.     } while(timeLeft > 0);
44. 
45.     return orders;
46. }

I copy pasted the tests it's used to explain the problem in the instructions:

console.log(timeToMixJuice('Tropical Island'));
console.log(timeToMixJuice('Berries & Lime'));
console.log(limesToCut(25, ['small', 'small', 'large', 'medium', 'small']));
console.log(remainingOrders(5, ['Energizer', 'All or Nothing', 'Green Garden']));

And here's the output I get for running this file on VScode (Which is the same as in the instruction):

3
2.5
4
[ 'Green Garden' ]

Upgrade to version 3 spec

If possible, this test runner should be updated to version 3 of the test runner interface specification. In version 3, one additional feature is enabled: the ability to link individual tests to tasks. This allows the website to show which tests belong to which tasks.

The way tests are linked to tasks is via an (optional) task_id field, which is an integer that matches the number of the task as defined in the exercise's instructions.md file (note: the instructions start at index 1).

This is an example of a test in the results.json file:

{
  "name": "Expected oven time in minutes",
  "status": "pass",
  "task_id": 1,
  "test_code": "Assert.Equal(40, Lasagna.ExpectedMinutesInOven());"
}

You are completely free in how to implement this. Some options are:

  1. Add metadata to a test that the test runner can then discover while running the tests (e.g. an attribute or annotation)
  2. Define a test name/task id mapping (e.g. in the exercise's .meta/config.json file)
  3. Any other option you can think of...

Let me know if there are any questions.

"Elyses Enchantments" removeItemAtBottom function TEST is not working properly

Below code is for testing the removeItemAtBottom function in Elyses Enchantments problem. But, It's seems to be not working expectedly. Because, the removeItemAtBottom function returs the stack after removing the bottom element. But, In the test code there is no catching the returned stack. Attached the snapshot of the issue for the reference.

Code issue

const stack = [1, 2, 3];
removeItemAtBottom(stack);
removeItemAtBottom(stack);
const expected = [3];
expect(stack).toStrictEqual(expected);

Code Have tobe :

let stack = [1, 2, 3];
stack = removeItemAtBottom(stack);
stack = removeItemAtBottom(stack);
const expected = [3];
expect(stack).toStrictEqual(expected);


Snapshot for Reference:

Elyses_Enchantments_test_case_issue

Prepare to upgrade runner to jest-circus

https://www.npmjs.com/package/jest-circus

This will be the test-runner by default at some point; and it will break this repository. We can get ahead of the game by checking out what the "damage" will be, and what effort is required to upgrade to this runner. It might give us quite a few things we want, as it allows you to not inject globals, get the test name during beforeEach etc.

Upgrade to version 3 spec

If possible, this test runner should be updated to version 3 of the test runner interface specification. In version 3, one additional feature is enabled: the ability to link individual tests to tasks. This allows the website to show which tests belong to which tasks.

The way tests are linked to tasks is via an (optional) task_id field, which is an integer that matches the number of the task as defined in the exercise's instructions.md file (note: the instructions start at index 1).

This is an example of a test in the results.json file:

{
  "name": "Expected oven time in minutes",
  "status": "pass",
  "task_id": 1,
  "test_code": "Assert.Equal(40, Lasagna.ExpectedMinutesInOven());"
}

You are completely free in how to implement this. Some options are:

  1. Add metadata to a test that the test runner can then discover while running the tests (e.g. an attribute or annotation)
  2. Define a test name/task id mapping (e.g. in the exercise's .meta/config.json file)
  3. Any other option you can think of...

Let me know if there are any questions.

Docker permission error

If I try to run the test runner in Docker using ./run-in-docker.sh leap ../javascript/exercises/practice/leap ../javascript/exercises/practice/leap (which assumes there is a sibling javascript repo checked out), I get an error:

Using reporter : /opt/test-runner/dist/reporter.js
Using test-root: /solution/
Using base-root: /opt/test-runner
Using setup-env: /opt/test-runner/dist/jest/setup.js
Using /solution/.meta/config.json as base configuration
Enabling tests in /solution/leap.spec.js
sed: couldn't open temporary file /solution/sedXo2Ajt: Permission denied
sed: couldn't open temporary file /solution/sedaMcAZw: Permission denied
sed: couldn't open temporary file /solution/sedNuro8w: Permission denied

This transformation is done in prepare.sh. If I run ls -al in prepare.sh to check the permissions, I get:

drwxr-xr-x 4 node node 4096 May 12 11:45 .
drwxr-xr-x 1 root root 4096 May 12 11:48 ..
drwxr-xr-x 2 node node 4096 May 12 11:45 .docs
-rw-r--r-- 1 node node  318 May 12 11:45 .eslintrc
drwxr-xr-x 2 node node 4096 May 12 11:45 .meta
-rw-r--r-- 1 node node   12 May 12 11:45 .npmrc
-rw-r--r-- 1 node node 1065 May 12 11:45 LICENSE
-rw-r--r-- 1 node node  252 May 12 11:45 babel.config.js
-rw-r--r-- 1 node node  248 May 12 11:45 leap.js
-rw-r--r-- 1 node node 1107 May 12 11:45 leap.spec.js
-rw-r--r-- 1 node node  816 May 12 11:45 package.json

The Dockerfile specifies that the image is run as user appuser, which then doesn't have the required permissions.

The master branch will be renamed to main

In line with our new org-wide policy, the master branch of this repo will be renamed to main. All open PRs will be automatically repointed.

GitHub will show you a notification about this when you look at this repo after renaming:

Screenshot 2021-01-27 at 15 31 45

In case it doesn't, this is the command it suggests:

git branch -m master main
git fetch origin
git branch -u origin/main main

You may like to update the primary branch on your forks too, which you can do under Settings->Branches and clicking the pencil icon on the right-hand-side under Default Branch:

Screenshot 2021-01-27 at 18 50 08

We will post a comment below when this is done. We expect it to happen within the next 12 hours.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.