Mocha tests passing on localhost but not when running on TravisCI - node.js

I've written a test suite like so:
this.slow(1000)
this.timeout(6000)
var response, client
before(function(done) {
client = new UsergridClient()
client.GET(_collection, function(err, r) {
response = r
done()
})
})
it('should not fail when a callback function is not passed', function() {
// note: this test will NOT fail gracefully inside the Mocha event chain
client.GET(_collection)
})
it('should return a 200 ok', function() {
// ******** LOGGING ********* //
console.log(response)
// ******** LOGGING ********* //
response.statusCode.should.equal(200)
})
it('response.entities should be an array', function() {
response.entities.should.be.an.Array
})
it('response.first should exist and have a valid uuid', function() {
response.first.should.be.an.Object.with.property('uuid').with.a.lengthOf(36)
})
it('response.entity should exist and have a valid uuid', function() {
response.entity.should.be.an.Object.with.property('uuid').with.a.lengthOf(36)
})
it('response.last should exist and have a valid uuid', function() {
response.last.should.be.an.Object.with.property('uuid').with.a.lengthOf(36)
})
When running this test locally, all tests pass. When running on TravisCI though, the response variables are being reported as undefined even inside the tests. This suggests to me that there's some sort of asynchronous mixup, but using the done() callback on the before() should mitigate that, shouldn't it? I even tried adding done callbacks to every subsequent test, but that still isn't working.
The notable error here is:
TypeError: Cannot read property 'property' of undefined
and it looks like that's being thrown from:
response.first.should.be.an.Object.with.property('uuid').with.a.lengthOf(36)
which makes me think Travis' environment doesn't like Object.with or maybe even just .with?
Here's my .travis.yml file:
language: node_js
node_js:
- '5.1.0'
install:
- 'npm install'
- 'npm -g install mocha'
script:
- 'mocha tests'
And here's the run log:
Using worker: worker-linux-docker-7421b08d.prod.travis-ci.org:travis-linux-8
system_info
Build system information
Build language: node_js
Build group: stable
Build dist: precise
Build image provisioning date and time
Thu Feb 5 15:09:33 UTC 2015
Operating System Details
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
Linux Version
3.13.0-29-generic
Cookbooks Version
a68419e https://github.com/travis-ci/travis-cookbooks/tree/a68419e
GCC version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Pre-installed Ruby versions
ruby-1.9.3-p551
Pre-installed Node.js versions
v0.10.36
Pre-installed Go versions
1.4.1
Redis version
redis-server 2.8.19
riak version
2.0.2
MongoDB version
MongoDB 2.4.12
CouchDB version
couchdb 1.6.1
Neo4j version
1.9.4
RabbitMQ Version
3.4.3
ElasticSearch version
1.4.0
Installed Sphinx versions
2.0.10
2.1.9
2.2.6
Default Sphinx version
2.2.6
Installed Firefox version
firefox 31.0esr
PhantomJS version
1.9.8
ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/local/maven
Java version: 1.7.0_76, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-29-generic", arch: "amd64", family: "unix"
git.checkout
0.36s$ git clone... cloning
remote: Counting objects: 315, done.
remote: Compressing objects: 100% (153/153), done.
remote: Total 315 (delta 74), reused 0 (delta 0), pack-reused 161
Receiving objects: 100% (315/315), 48.32 KiB | 0 bytes/s, done.
Resolving deltas: 100% (156/156), done.
Checking connectivity... done.
$ cd path/to/proj
$ git checkout -qf <hash>
This job is running on container-based infrastructure, which does not allow use of 'sudo', setuid and setguid executables.
If you require sudo, add 'sudo: required' to your .travis.yml
See http://docs.travis-ci.com/user/workers/container-based-infrastructure/ for details.
3.13s$ nvm install 5.1.0
######################################################################## 100.0%
Checksums empty
Now using node v5.1.0
$ node --version
v5.1.0
$ npm --version
3.3.12
$ nvm --version
0.23.3
install.1
17.95s$ npm install
npm WARN engine underscore.inflection#1.3.0: wanted: {"node":">=0.10.0 <0.12"} (current: {"node":"5.1.0","npm":"3.3.12"})
npm WARN deprecated lodash#0.9.2: lodash#<3.0.0 is no longer maintained. Upgrade to lodash#^3.0.0.
npm WARN deprecated lodash#2.4.2: lodash#<3.0.0 is no longer maintained. Upgrade to lodash#^3.0.0.
app#2.0.0 /home/travis/build/path/to/app
... list of packages
npm WARN EPACKAGEJSON app#2.0.0 No repository field.
install.2
1.71s$ npm -g install mocha
/home/travis/.nvm/versions/node/v5.1.0/bin/mocha -> /home/travis/.nvm/versions/node/v5.1.0/lib/node_modules/mocha/bin/mocha
/home/travis/.nvm/versions/node/v5.1.0/bin/_mocha -> /home/travis/.nvm/versions/node/v5.1.0/lib/node_modules/mocha/bin/_mocha
/home/travis/.nvm/versions/node/v5.1.0/lib
... list of packages
1.50s$ mocha tests
init() / initSharedInstance()
✓ should be an instance of Client
Client
initialization
✓ should fail to initialize without an orgId and appId
✓ should initialize using properties defined in config.json
✓ should initialize when passing orgId and appId as arguments, taking precedence over config
✓ should initialize when passing an object containing orgId and appId, taking precedence over config
GET()
IncomingMessage {
_readableState:
... omitted
readable: false,
domain: null,
headers:
... omitted
client:
... omitted
req:
... omitted
request:
... omitted
toJSON: [Function: responseToJSON],
caseless:
Caseless {
dict:
{ 'access-control-allow-origin': '*',
'content-type': 'application/json',
date: 'Sun, 29 Nov 2015 22:44:54 GMT',
server: 'Apache-Coyote/1.1',
'set-cookie': [Object],
'transfer-encoding': 'chunked',
connection: 'Close' } },
read: [Function],
body:
{ action: 'get',
application: '19748000-24b6-11e3-9877-6d1a3f81ba2f',
params: {},
path: '/tests',
uri: 'https://api.mydomain.com/myorg/sandbox/tests',
entities:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ],
timestamp: 1448837094623,
duration: 65,
organization: 'myorg',
applicationName: 'sandbox',
cursor: 'LTU2ODc0MzQzOkdCcGJDbVpTRWVXVndibnE5RUdORGc',
count: 7 },
entities:
[ ],
first:
{ uuid: 'b3037a1a-4cd6-11e5-8aa2-0b8eb3ce43ee',
type: 'test',
name: '01',
created: 1440692071473,
modified: 1440692071473,
food: 'pizza',
metadata: { path: '/tests/b3037a1a-4cd6-11e5-8aa2-0b8eb3ce43ee' },
value: 1 },
entity:
{ uuid: 'b3037a1a-4cd6-11e5-8aa2-0b8eb3ce43ee',
type: 'test',
name: '01',
created: 1440692071473,
modified: 1440692071473,
food: 'pizza',
metadata: { path: '/tests/b3037a1a-4cd6-11e5-8aa2-0b8eb3ce43ee' },
value: 1 },
last:
{ uuid: '181a5b0a-6652-11e5-95c1-b9eaf4418d0e',
type: 'test',
created: 1443493848240,
modified: 1443493848240,
metadata: { path: '/tests/181a5b0a-6652-11e5-95c1-b9eaf4418d0e' },
title: 'Charlotte\'s Web' } }
✓ should not fail when a callback function is not passed
✓ should return a 200 ok
✓ response.entities should be an array
1) response.first should exist and have a valid uuid
2) response.entity should exist and have a valid uuid
3) response.last should exist and have a valid uuid
POST()
✓ should not fail when a callback function is not passed
✓ should return a 200 ok
4) response.entities should be an array
5) response.entity should exist and have a valid uuid
✓ response.entity.author should equal "Sir Arthur Conan Doyle"
PUT()
✓ should not fail when a callback function is not passed
✓ should return a 200 ok
6) response.entities should be an array
7) response.entity should exist and its uuid should the uuid from the previous POST requets
✓ response.entity.narrator should equal "Peter Doyle"
DELETE()
✓ should not fail when a callback function is not passed
✓ should return a 200 ok
✓ response.error.name should equal "service_resource_not_found"
authenticateApp()
✓ should return a 200 ok
✓ should have a valid token
✓ client.appAuth.token should be set to the token returned from
✓ client.appAuth.expiry should be set to a future date
appAuth / setAppAuth()
✓ should initialize by passing a list of arguments
✓ should initialize by passing an object
✓ should initialize by passing an instance of AppAuth
✓ should initialize by setting to an instance of AppAuth
Query
_type
✓ query._type should equal "cats" when passing "type" as a parameter to Query
✓ query._type should equal "cats" when calling .type() builder method
✓ query._type should equal "cats" when calling .collection() builder method
_limit
✓ query._limit should equal 10
_ql
✓ should support complex builder syntax (chained constructor methods)
✓ not operator should precede conditional statement
✓ string values should be contained in single quotes
✓ boolean values should not be contained in single quotes
✓ float values should not be contained in single quotes
✓ integer values should not be contained in single quotes
✓ uuid values should not be contained in single quotes
36 passing (696ms)
7 failing
1) Client GET() response.first should exist and have a valid uuid:
TypeError: Cannot read property 'property' of undefined
at Context.<anonymous> (tests/lib/client.test.js:69:48)
2) Client GET() response.entity should exist and have a valid uuid:
TypeError: Cannot read property 'property' of undefined
at Context.<anonymous> (tests/lib/client.test.js:73:49)
3) Client GET() response.last should exist and have a valid uuid:
TypeError: Cannot read property 'property' of undefined
at Context.<anonymous> (tests/lib/client.test.js:77:47)
4) Client POST() response.entities should be an array:
TypeError: Cannot read property 'a' of undefined
at Context.<anonymous> (tests/lib/client.test.js:108:50)
5) Client POST() response.entity should exist and have a valid uuid:
TypeError: Cannot read property 'property' of undefined
at Context.<anonymous> (tests/lib/client.test.js:112:49)
6) Client PUT() response.entities should be an array:
TypeError: Cannot read property 'a' of undefined
at Context.<anonymous> (tests/lib/client.test.js:146:50)
7) Client PUT() response.entity should exist and its uuid should the uuid from the previous POST requets:
TypeError: Cannot read property 'property' of undefined
at Context.<anonymous> (tests/lib/client.test.js:150:49)
The command "mocha tests" exited with 7.
Done. Your build exited with 1.

Somehow, I'm not entirely sure how, this syntax was working fine using whatever version of should.js I had installed locally. When deploying to TravisCI, it must have installed a newer version which caused any type-checking assertion to fail.
Where this previously worked (according to this):
response.first.should.be.an.Object.with.property('uuid').with.a.lengthOf(36)
It actually needed to be called with parentheses:
response.first.should.be.an.Object().with.property('uuid').with.a.lengthOf(36)
// ^^
... as indicated in the official docs.

Related

Validation Error in running Hyperledger Caliper V0.4.2 with Fabric 2.1

When I have been running the Caliper V0.4.2 for measuring the benchmarks of Fabric 2.1.0 1.4.7, I got the below error
ValidationError: child "version" fails because ["version" must be one of [1.0]]. child "clients" fails because ["clients" is required]. child "channels" fails because ["channels" must be an object]. child "organizations" fails because ["organizations" must be an object]. child "orderers" fails because ["orderers" is required]. child "peers" fails because ["peers" is required]
at Object.exports.process (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/errors.js:202:19)
at internals.Object._validateWithOptions (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/types/any/index.js:763:31)
at module.exports.internals.Any.root.validate (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hapi/joi/lib/index.js:145:23)
at Function._validateTopLevel (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/configValidator.js:208:26)
at Function.validateNetwork (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/configValidator.js:58:25)
at new FabricConnector (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/fabric-connector.js:107:25)
at CaliperEngine.connectorFactory [as adapterFactory] (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-fabric/lib/connectorFactory.js:26:23)
at CaliperEngine.run (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-core/lib/manager/caliper-engine.js:93:36)
at Function.handler (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-cli/lib/launch/lib/launchManager.js:62:43)
at Object.module.exports.handler (/home/gow/fabric-benchmarks/caliper-benchmarks/node_modules/#hyperledger/caliper-cli/lib/launch/launchManagerCommand.js:46:44)
isJoi: true,
name: 'ValidationError',
details:
[ { message: '"version" must be one of [1.0]',
path: [Array],
type: 'any.allowOnly',
context: [Object] },
{ message: '"clients" is required',
path: [Array],
type: 'any.required',
context: [Object] },
{ message: '"channels" must be an object',
path: [Array],
type: 'object.base',
context: [Object] },
{ message: '"organizations" must be an object',
path: [Array],
type: 'object.base',
context: [Object] },
{ message: '"orderers" is required',
path: [Array],
type: 'any.required',
context: [Object] },
{ message: '"peers" is required',
path: [Array],
type: 'any.required',
context: [Object] } ],
_object:
{ name: 'Caliper Benchmarks',
version: '2.1.0',
caliper: { blockchain: 'fabric' },
channels: [ [Object] ],
organizations: [ [Object] ] },
annotate: [Function] }
Command that I run are,
npm init -y
npm install --only=prod #hyperledger/caliper-cli#0.4.0
npx caliper bind --caliper-bind-sut fabric:2.1
./network.sh deployCC -ccn simple -ccp ../../caliper-benchmarks/src/fabric/scenario/simple/node -ccl javascript
npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/fabric/test-network.yaml --caliper-benchconfig benchmarks/scenario/simple/config.yaml --caliper-flow-only-test --caliper-fabric-gateway-enabled
Hyperledger network creation, channel creation and Chaincode deployment all were successful.
How to solve this error?
Looks like you are using the main branch of caliper-benchmarks. I would suggest you https://github.com/hyperledger/caliper-benchmarks/blob/main/networks/fabric/README.md
From what you have posted, you should use the latest available version of caliper which is 0.4.2, not 0.4.0. To do so the command you should issue is
npm install --only=prod #hyperledger/caliper-cli
You should bind to the latest 2.2 sdk (don't bind to 2.1 as fabric doesn't support 2.1). Note this is selecting the version of the sdk used to interact with a fabric network, not the version of the fabric network you are using. 2.2 will work with a fabric 2.2 and later 2.x versions
npx caliper bind --caliper-bind-sut fabric:2.2
Finally it looks like you tried to change the version number in the network configuration file. Don't change the version (it must be 2.0.0) as it refers to the version of the network configuration file and not the version of fabric you want to test
As you look to be using test-network, depending on which branch of fabric-samples you are using defines the version of fabric. The main branch tests the latest version of fabric which should have no problems.

Jest detects open redis client on travis-ci

I encountered some difficulties with redis testing on travis-ci.
Here is the redis setup code,
async function getClient() {
const redisClient = createClient({
socket: {
url: redisConfig.connectionString,
reconnectStrategy: (currentNumberOfRetries: number) => {
if (currentNumberOfRetries > 1) {
throw new Error("max retries reached");
}
return 1000;
},
},
});
try {
await redisClient.connect();
} catch (e) {
console.log(e);
}
return redisClient;
}
Here is the travis config, note that I run npm install redis because it is listed as a peer dependency.
language: node_js
node_js:
- "14"
dist: focal # ubuntu 20.04
services:
- postgresql
- redis-server
addons:
postgresql: "13"
apt:
packages:
- postgresql-13
env:
global:
- PGUSER=postgres
- PGPORT=5432 # for some reason unlike what documentation says, the port is 5432
jobs:
- NODE_ENV=ci
cache:
directories:
- node_modules
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- postgres --version
- pg_lsclusters # shows port of postgresql, ubuntu specific command
install:
- npm i
- npm i redis
before_script:
- sudo psql -c 'create database orm_test;' -p 5432 -U postgres
script:
- npm run test-detectopen
The first issue is this missing client.connect function, whereas connection on my local machine with redis-server running works.
console.log
TypeError: redisClient.connect is not a function
at Object.getClient (/home/travis/build/sunjc826/mini-orm/src/connection/redis/index.ts:21:23)
at Function.init (/home/travis/build/sunjc826/mini-orm/src/data-mapper/index.ts:33:30)
at /home/travis/build/sunjc826/mini-orm/src/lib-test/tests/orm.test.ts:25:20
at Promise.then.completed (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/utils.js:390:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/utils.js:315:10)
at _callCircusHook (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/run.js:181:40)
at _runTestsForDescribeBlock (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/run.js:47:7)
at run (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/run.js:25:3)
at runAndTransformResultsToJestFormat (/home/travis/build/sunjc826/mini-orm/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:166:21)
The second is this open handle issue, on my local machine, even if connection fails, jest does not give such an error and exits cleanly.
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPWRAP
7 |
8 | async function getClient() {
> 9 | const redisClient = createClient({
| ^
10 | socket: {
11 | url: redisConfig.connectionString,
12 | reconnectStrategy: (currentNumberOfRetries: number) => {
at RedisClient.Object.<anonymous>.RedisClient.create_stream (node_modules/redis/index.js:196:31)
at new RedisClient (node_modules/redis/index.js:121:10)
at Object.<anonymous>.exports.createClient (node_modules/redis/index.js:1023:12)
at Object.getClient (src/connection/redis/index.ts:9:23)
at Function.init (src/data-mapper/index.ts:33:30)
at src/lib-test/tests/orm.test.ts:25:20
at TestScheduler.scheduleTests (node_modules/#jest/core/build/TestScheduler.js:333:13)
at runJest (node_modules/#jest/core/build/runJest.js:387:19)
at _run10000 (node_modules/#jest/core/build/cli/index.js:408:7)
at runCLI (node_modules/#jest/core/build/cli/index.js:261:3)
It turns out that this is likely caused by redis being a peer dependency.
Listing out node-redis versions, I'm guessing the version tagged latest (as of time writing 3.1.2) was installed instead of the version 4+.
So, I moved redis to regular dependencies instead.

Error when trying to use CanvasJS via RequireJS

I'm trying to use CanvasJS inside my project. I'm using RequireJS to manage the modules, and have this in the main script:
define(['domReady',"canvasjs","common-functions"], function(domReady,CanvasJS) {
domReady(function () {
window.CanvasJS = CanvasJS;
init_page_select();
});
});
This is what I have in my requireJS config file for the path:
"paths": {
// other stuff here
"canvasjs": "node_modules/canvasjs/dist/canvasjs.min"
},
I can see the canvasjs.min.js file being grabbed fine - but then I get this weird error:
ReferenceError: intToHexColorString is not defined[Learn More] canvasjs.min.js:7:7042
[33]</n.prototype.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:7:7042
[28]</n.prototype.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:5:14150
n/this.render https://www.test.org/2018/js/lib/node_modules/canvasjs/dist/canvasjs.min.js:8:17771
init_page_select https://www.test.org/2018/js/lib/spot_view_stats.js:83:2
<anonymous> https://www.test.org/2018/js/lib/spot_view_stats.js:4:3
domReady https://www.test.org/2018/js/lib/domready.js:105:13
<anonymous> https://www.test.org/2018/js/lib/spot_view_stats.js:2:2
execCb https://www.test.org/2018/js/lib/require.js:5:12859
check https://www.test.org/2018/js/lib/require.js:5:6575
enable/</< https://www.test.org/2018/js/lib/require.js:5:9031
bind/< https://www.test.org/2018/js/lib/require.js:5:812
emit/< https://www.test.org/2018/js/lib/require.js:5:9497
each https://www.test.org/2018/js/lib/require.js:5:289
emit https://www.test.org/2018/js/lib/require.js:5:9465
check https://www.test.org/2018/js/lib/require.js:5:7169
enable/</< https://www.test.org/2018/js/lib/require.js:5:9031
bind/< https://www.test.org/2018/js/lib/require.js:5:812
emit/< https://www.test.org/2018/js/lib/require.js:5:9497
each https://www.test.org/2018/js/lib/require.js:5:289
emit https://www.test.org/2018/js/lib/require.js:5:9465
check https://www.test.org/2018/js/lib/require.js:5:7169
enable https://www.test.org/2018/js/lib/require.js:5:9358
init https://www.test.org/2018/js/lib/require.js:5:5716
h https://www.test.org/2018/js/lib/require.js:5:4287
completeLoad https://www.test.org/2018/js/lib/require.js:5:12090
onScriptLoad https://www.test.org/2018/js/lib/require.js:5:13014
I'm invoking it with:
var chart = new CanvasJS.Chart("thegraph",
{
title:{
text: impressionText
},
theme: "theme2",
axisX: {
valueFormatString: "MMM-DD-YYYY",
labelAngle: -50
},
axisY:{
valueFormatString: "#0",
title: impressionText
},
data: [
{
type: "line",
showInLegend: true,
legendText: legendText,
dataPoints: dataPoints
}
]
});
chart.render();
Interestingly, if I tell it to load canvasjs.js instead of canvasjs.min.js, I get another error:
ReferenceError: intToHexColorString is not defined[Learn More]
OK so the problem seemed to be my version. For some reason "npm install canvasjs" was installing 1.8.1, but 2.2 was out. As per their request, I updated it to 2.2 and it sorted the problem. It seems weird npm is running such an outdated version though

Google closure gives error while javascript minificatation

I am using google-closure-compiler grunt task to minify javascript files. I've defined task like : -
'closure-compiler': {
deviceDetails: {
files: {
'target.min.js: 'source.js'
},
options: {
compilation_level: 'SIMPLE'
}
// args: [
// '--js', 'source.js',
// '--compilation_level', 'SIMPLE',
// '--js_output_file', 'out.js',
// '--debug'
// ]
}
This gives me an error
[ { '29': 1,
_state: 2,
_result: [Error: not implemented],
_subscribers: [] } ]
Warning: Compilation error Use --force to continue.
Aborted due to warnings.
Earlier I was facing promise issue , for that I installed pollyfill module.
require('es6-promise').polyfill();
I am running npm 1.3.10 version and Unfortunately, I can't upgrade it right now.
Also , followed alternative approach of using args.. still facing same error.
So after bit analysis, I am using below two grunt plugin's
1. grunt-closure-tools
2. google-closure-compiler
Its was a problem with legacy npm version.

Error importing Node.js modules into Intern tests

I'm trying out Intern for testing our Node.js modules. I've got it set up to run an empty test and even require node modules, but when I try to require one of the modules in our package I get the error:
/path/to/app/node_modules/path/path.js:327
var path = (i >= 0) ? arguments[i] : process.cwd();
^
TypeError: undefined is not a function
at Object.exports.resolve (/path/to/app/node_modules/path/path.js:327:52)
at Object.exports.relative (/path/to/app/node_modules/path/path.js:405:20)
at getSource (/path/to/app/node_modules/intern/lib/util.js:368:21)
at formatLine (/path/to/app/node_modules/intern/lib/util.js:405:40)
at processChromeTrace (/path/to/app/node_modules/intern/lib/util.js:418:16)
at normalizeStackTrace (/path/to/app/node_modules/intern/lib/util.js:470:38)
at Object.getErrorMessage (/path/to/app/node_modules/intern/lib/util.js:597:14)
at PreExecutor._handleError (/path/to/app/node_modules/intern/lib/executors/PreExecutor.js:256:24)
at /path/to/app/node_modules/intern/node_modules/dojo/lang.js:78:32
at process.<anonymous> (/path/to/app/node_modules/intern/lib/executors/PreExecutor.js:302:6)
Folder structure is:
src/
**/*.coffee
tests
unit/**/*.coffee
intern.js
js/ (coffeescript is compiled here)
src/
**/*.js
tests/
**/*.js
all.js (compiled by rolling up the names of the other tests under /js/tests)
node_modules
Here's my intern.js:
define({
capabilities: {
'browserstack.selenium_version': '2.45.0'
},
environments: [
{browserName: 'internet explorer', version: '11', platform: 'WIN8'},
{browserName: 'internet explorer', version: '10', platform: 'WIN8'},
{browserName: 'internet explorer', version: '9', platform: 'WINDOWS'},
{browserName: 'firefox', version: '37', platform: ['WINDOWS', 'MAC']},
{browserName: 'chrome', version: '39', platform: ['WINDOWS', 'MAC']},
{browserName: 'safari', version: '8', platform: 'MAC'}
],
maxConcurrency: 2,
tunnel: 'BrowserStackTunnel',
loaderOptions: {
packages: [{name: 'app', location: 'js/src'}]
},
reporters: ['Console', 'Lcov'],
suites: ['js/tests/unit/all'],
excludeInstrumentation: /^(?:\.npm|js\/tests|src|tests|node_modules)\//
});
My test is just:
define (require) ->
registerSuite = require('intern!object')
assert = require('intern/chai!assert')
SchemaBuilder = require('intern/dojo/node!app/path/to/Module')
registerSuite
name: 'Testing'
'test': ->
From the project root I'm running './node_modules/.bin/intern-client config=tests/intern'
Is this a problem with my code, configuration, environment, or Intern?
I've tried with Node.js v0.12.0 and v0.12.7.
Interestingly, removing the path module from my app dependencies (package.json) resolved (well, avoided) the undefined is not a function error, seemingly falling back on Intern's own path resolution. I don't really know why, but this seems like a bug.
This presented a new, more tractable error: Error: Cannot find module 'app/path/to/Module', suggesting the path in the require() was simply wrong.
I think the problem is that the intern/dojo/node loader doesn't support the loaderOptions: {packages: [{name: 'app', location: 'js/src'}]} configuration, and hence it is searching for an app directory relative to the test module. If I replace app/ with ../../../../js/src/ then it resolves and works as expected.
It's a bit ugly, but it's the standard way of requiring local files in node, so it's also not too surprising, I had just hoped Intern's loader could make it cleaner.

Resources