Skip to content

test: improve coverage of lib/internal/loader/ModuleMap.js - #16061

Closed
jphblais wants to merge 1 commit into
nodejs:masterfrom
jphblais:upstream
Closed

test: improve coverage of lib/internal/loader/ModuleMap.js#16061
jphblais wants to merge 1 commit into
nodejs:masterfrom
jphblais:upstream

Conversation

@jphblais

@jphblaisjphblais commented Oct 7, 2017

Copy link
Copy Markdown
Contributor

Added tests to cover the exceptions "throw'ed" in ModuleMap class.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

@nodejs-github-botnodejs-github-bot added the test Issues and PRs related to the tests. label Oct 7, 2017
@mscdexmscdex added the esm Issues and PRs related to the ECMAScript Modules implementation. label Oct 7, 2017
@TrottTrott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 7, 2017
@vsemozhetbyt

vsemozhetbyt commented Oct 7, 2017

Copy link
Copy Markdown
Contributor

@jphblais, hi. Thank you for contributions!

It may be better to use new branches for different PRs, so that their commits are not duplicated and mixed.

@bmeckbmeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nit on comment is not blocking.


// As long as the assertion of "job" argument is done after the assertion of
// "url" argument this test suite is ok. Tried to mock the "job" parameter,
// but I think it's useless, and was not simple to mock...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the extra text, I think the first sentence is enough:

Tried to mock the "job" parameter, but I think it's useless, and was not simple to mock...


assert.throws(() => moduleMap.has(1), errorReg);

assert.throws(() => moduleMap.has(() => {}), errorReg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We don't really need to keep all of the assertions separated by empty lines, and we usually don't do it for single-line assertions. I think it mostly blows up the visual file size in this case.

@BridgeAR

Copy link
Copy Markdown
Member

@lance

lance commented Oct 9, 2017

Copy link
Copy Markdown
Member

CI has some failures that appear to be unrelated.

smartos15-64
not ok 216 parallel/test-benchmark-string_decoder
---
duration_ms: 120.583
severity: fail
stack: |-
timeout
...
smartos16-64
not ok 144 parallel/test-benchmark-os
---
duration_ms: 1.330
severity: fail
stack: |-
fs.js:918
return binding.readdir(pathModule.toNamespacedPath(path), options.encoding);
^
Error: ENOENT: no such file or directory, scandir '/home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/benchmark/tmp'
at Object.fs.readdirSync (fs.js:918:18)
at /home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/benchmark/_cli.js:13:31
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/benchmark/_cli.js:12:4)
at Module._compile (module.js:600:30)
at Object.Module._extensions..js (module.js:611:10)
at Module.load (module.js:521:32)
at tryModuleLoad (module.js:484:12)
at Function.Module._load (module.js:476:3)
at Module.require (module.js:544:17)
assert.js:45
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: 1 === 0
at ChildProcess.child.on (/home/iojs/build/workspace/node-test-commit-smartos/nodes/smartos16-64/test/common/benchmark.js:25:12)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:210:12)
0,pi3-raspbian-jessie
FATAL: remote file operation failed: /home/iojs/build/workspace/node-test-binary-arm@tmp/secretFiles/d521ffff-6068-42ba-9cc9-5e26f22ef2fa at hudson.remoting.Channel@44c3e069:JNLP4-connect connection from static-n49-176-213-208.sbr2.nsw.optusnet.com.au/49.176.213.208:48902: java.io.IOException: Unable to delete '/home/iojs/build/workspace/node-test-binary-arm@tmp/secretFiles/d521ffff-6068-42ba-9cc9-5e26f22ef2fa/.nfs00000000001c9bfb00000013'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
java.nio.file.FileSystemException: /home/iojs/build/workspace/node-test-binary-arm@tmp/secretFiles/d521ffff-6068-42ba-9cc9-5e26f22ef2fa/.nfs00000000001c9bfb00000013: Device or resource busy
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
at java.nio.file.Files.deleteIfExists(Files.java:1165)
at hudson.Util.tryOnceDeleteFile(Util.java:287)
at hudson.Util.deleteFile(Util.java:243)
at hudson.FilePath.deleteRecursive(FilePath.java:1209)
at hudson.FilePath.deleteContentsRecursive(FilePath.java:1218)
at hudson.FilePath.deleteRecursive(FilePath.java:1200)
at hudson.FilePath.access$1000(FilePath.java:195)
at hudson.FilePath$14.invoke(FilePath.java:1179)
at hudson.FilePath$14.invoke(FilePath.java:1176)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2731)
at hudson.remoting.UserRequest.perform(UserRequest.java:153)
at hudson.remoting.UserRequest.perform(UserRequest.java:50)
at hudson.remoting.Request$2.run(Request.java:336)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at hudson.remoting.Engine$1$1.run(Engine.java:94)
at java.lang.Thread.run(Thread.java:745)
Caused: java.io.IOException: Unable to delete '/home/iojs/build/workspace/node-test-binary-arm@tmp/secretFiles/d521ffff-6068-42ba-9cc9-5e26f22ef2fa/.nfs00000000001c9bfb00000013'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
at hudson.Util.deleteFile(Util.java:248)
at hudson.FilePath.deleteRecursive(FilePath.java:1209)
at hudson.FilePath.deleteContentsRecursive(FilePath.java:1218)
at hudson.FilePath.deleteRecursive(FilePath.java:1200)
at hudson.FilePath.access$1000(FilePath.java:195)
at hudson.FilePath$14.invoke(FilePath.java:1179)
at hudson.FilePath$14.invoke(FilePath.java:1176)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2731)
at hudson.remoting.UserRequest.perform(UserRequest.java:153)
at hudson.remoting.UserRequest.perform(UserRequest.java:50)
at hudson.remoting.Request$2.run(Request.java:336)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at hudson.remoting.Engine$1$1.run(Engine.java:94)
at java.lang.Thread.run(Thread.java:745)
at ......remote call to JNLP4-connect connection from static-n49-176-213-208.sbr2.nsw.optusnet.com.au/49.176.213.208:48902(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1545)
at hudson.remoting.UserResponse.retrieve(UserRequest.java:253)
at hudson.remoting.Channel.call(Channel.java:830)
at hudson.FilePath.act(FilePath.java:985)
Caused: java.io.IOException: remote file operation failed: /home/iojs/build/workspace/node-test-binary-arm@tmp/secretFiles/d521ffff-6068-42ba-9cc9-5e26f22ef2fa at hudson.remoting.Channel@44c3e069:JNLP4-connect connection from static-n49-176-213-208.sbr2.nsw.optusnet.com.au/49.176.213.208:48902
at hudson.FilePath.act(FilePath.java:992)
at hudson.FilePath.act(FilePath.java:974)
at hudson.FilePath.deleteRecursive(FilePath.java:1176)
at org.jenkinsci.plugins.credentialsbinding.impl.UnbindableDir$UnbinderImpl.unbind(UnbindableDir.java:84)
at org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper$1.tearDown(SecretBuildWrapper.java:113)
at hudson.model.Build$BuildExecution.doRun(Build.java:174)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1728)
at hudson.matrix.MatrixRun.run(MatrixRun.java:146)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)

I will self-assign and land this unless there are objections based on these test results.

@lancelance self-assigned this Oct 9, 2017
@bmeckbmeck mentioned this pull request Oct 9, 2017
2 tasks
@lancelance removed their assignment Oct 10, 2017

const moduleMap = new ModuleMap();

assert.throws(() => moduleMap.get({}), errorReg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can put these in a loop to adhere to the DRY principle:

[{},[],true,1,()=>{}].forEach((element)=>{assert.throws(()=>moduleMap.get(element),errorReg);});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should likely be made into...

common.expectsError(()=>moduleMap.get([]),{code: 'ERR_INVALID_ARG_TYPE',type: TypeError,message: /^The"url"argumentmustbeoftypestring/});

etc

@BridgeARBridgeAR self-assigned this Oct 18, 2017
@tniessen

Copy link
Copy Markdown
Member

Seems like this needs to be rebased.

@BridgeARBridgeAR removed their assignment Oct 20, 2017
@Trott

Copy link
Copy Markdown
Member

Obsoleted by #15924 from same author.

@TrottTrott closed this Oct 27, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-and-learnIssues related to the Code-and-Learn events and PRs submitted during the events.esmIssues and PRs related to the ECMAScript Modules implementation.testIssues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

14 participants

@jphblais@vsemozhetbyt@BridgeAR@lance@tniessen@Trott@bmeck@jasnell@addaleax@lpinca@TimothyGu@hiroppy@mscdex@nodejs-github-bot