Skip to content

Karma unit tests not working inside docker container assets #9181

Open
@vinay-deshmukh

Description

Description

I am trying to run the unit tests (for the files at ./media/js/base/.js, and the tests are at ./tests/unit/spec/base/.js) inside a docker container.

Steps to reproduce

The documentation mentions that I should be running npm run test to run the Jasmine/Karma tests(i.e. the unit tests).

So, I ran this command as follows:

docker-compose run assets npm run test

I tried doing that, and the linters give a lot of warnings, but then it finally gets to performing the karma unit tests.

The log output of this command is as follows (I have not included the linting log output):

bedrock@0.1.0 test /app
> karma start ./tests/unit/karma.conf.js
20 07 2020 13:42:19.042:INFO [karma-server]: Karma v4.3.0 server started at http://0.0.0.0:9876/
20 07 2020 13:42:19.047:INFO [launcher]: Launching browsers Firefox, Chrome with concurrency unlimited
20 07 2020 13:42:19.054:INFO [launcher]: Starting browser Firefox
20 07 2020 13:42:19.098:INFO [launcher]: Starting browser Chrome
20 07 2020 13:42:19.100:ERROR [launcher]: No binary for Chrome browser on your platform.
  Please, set "CHROME_BIN" env variable.
20 07 2020 13:43:19.087:WARN [launcher]: Firefox have not captured in 60000 ms, killing.
20 07 2020 13:43:21.091:WARN [launcher]: Firefox was not killed in 2000 ms, sending SIGKILL.
20 07 2020 13:43:23.095:WARN [launcher]: Firefox was not killed by SIGKILL in 2000 ms, continuing.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bedrock@0.1.0 test: `karma start ./tests/unit/karma.conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bedrock@0.1.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-07-20T13_43_23_124Z-debug.log

To see the log file, I did,

docker-compose run assets bash

And now run the command npm run test inside the container.

I get the same output as above, but now I can cat the log the file, and it contains:

root@d1603a0dc81a:/app# cat /root/.npm/_logs/2020-07-20T13_47_32_449Z-debug.log 
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using npm@6.14.5
3 info using node@v12.18.2
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle bedrock@0.1.0~pretest: bedrock@0.1.0
6 verbose lifecycle bedrock@0.1.0~pretest: unsafe-perm in lifecycle true
7 verbose lifecycle bedrock@0.1.0~pretest: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/app/node_modules/.bin:/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
8 verbose lifecycle bedrock@0.1.0~pretest: CWD: /app
9 silly lifecycle bedrock@0.1.0~pretest: Args: [ '-c', 'npm run lint' ]
10 silly lifecycle bedrock@0.1.0~pretest: Returned: code: 0  signal: null
11 info lifecycle bedrock@0.1.0~test: bedrock@0.1.0
12 verbose lifecycle bedrock@0.1.0~test: unsafe-perm in lifecycle true
13 verbose lifecycle bedrock@0.1.0~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/app/node_modules/.bin:/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
14 verbose lifecycle bedrock@0.1.0~test: CWD: /app
15 silly lifecycle bedrock@0.1.0~test: Args: [ '-c', 'karma start ./tests/unit/karma.conf.js' ]
16 silly lifecycle bedrock@0.1.0~test: Returned: code: 1  signal: null
17 info lifecycle bedrock@0.1.0~test: Failed to exec test script
18 verbose stack Error: bedrock@0.1.0 test: `karma start ./tests/unit/karma.conf.js`
18 verbose stack Exit status 1
18 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
18 verbose stack     at EventEmitter.emit (events.js:315:20)
18 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
18 verbose stack     at ChildProcess.emit (events.js:315:20)
18 verbose stack     at maybeClose (internal/child_process.js:1021:16)
18 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
19 verbose pkgid bedrock@0.1.0
20 verbose cwd /app
21 verbose Linux 5.6.13-100.fc30.x86_64
22 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
23 verbose node v12.18.2
24 verbose npm  v6.14.5
25 error code ELIFECYCLE
26 error errno 1
27 error bedrock@0.1.0 test: `karma start ./tests/unit/karma.conf.js`
27 error Exit status 1
28 error Failed at the bedrock@0.1.0 test script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]

Expected result

The unit tests should run, and let me know if there are any problems

Actual result

Karma gives errors like,

20 07 2020 13:43:19.087:WARN [launcher]: Firefox have not captured in 60000 ms, killing.
20 07 2020 13:43:21.091:WARN [launcher]: Firefox was not killed in 2000 ms, sending SIGKILL.
20 07 2020 13:43:23.095:WARN [launcher]: Firefox was not killed by SIGKILL in 2000 ms, continuing.

Environment

I am on Windows Home[10.0.18362.959] , using VirtualBox 6.0.22 to run a Fedora 30 VM, which has Docker Docker version 19.03.12, build 48a66213fe,

Since my host OS(Windows) does not support Docker, I had to use Fedora 30 to install docker.

Metadata

Assignees

No one assigned

    Labels

    BackendServer stuff yoP3Third level priority - Nice to have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions