Titanium JIRA Archive
Appcelerator Daemon (DAEMON)

[DAEMON-138] appcd-gulp: Coverage tests blow up when --trace-deprecation is set

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusResolved
ResolutionWon't Do
Resolution Date2020-05-07T14:44:31.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsappcd-gulp
Labelsn/a
ReporterChris Barber
AssigneeChris Barber
Created2017-11-14T17:25:21.000+0000
Updated2020-05-07T14:44:31.000+0000

Description

When trying to get a bit more info about unhandled rejections, Node.js has a flag that can be passed in called \-\-trace\-deprecation. The idea would be to add this to the gulp test/coverage task and then we'd see it in the CI logs. However, when this flag is set, for some reason nyc blows up because it can't load mocha-jenkins-reporter. But the rub is nyc is not supposed to load it. The mocha-jenkins-reporter is an argument to mocha, not nyc. When adding \-\-trace\-deprecation and running gulp coverage, we get the following error:
Error: Cannot find module '/Users/chris/appc/appc-daemon/node_modules/nyc/node_modules/istanbul-reports/lib/Users/chris/appc/appc-daemon/node_modules/mocha-jenkins-reporter'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.create (/Users/chris/appc/appc-daemon/node_modules/nyc/node_modules/istanbul-reports/index.js:10:20)
    at /Users/chris/appc/appc-daemon/node_modules/nyc/index.js:451:24
    at Array.forEach (<anonymous>)
    at NYC.report (/Users/chris/appc/appc-daemon/node_modules/nyc/index.js:450:17)
    at report (/Users/chris/appc/appc-daemon/node_modules/nyc/bin/nyc.js:89:7)
    at /Users/chris/appc/appc-daemon/node_modules/nyc/bin/nyc.js:76:25
We can fix that by applying the following patch:
+++ b/packages/appcd-gulp/src/templates/standard.js
@@ -159,6 +159,7 @@ module.exports = (opts) => {
        function runTests(cover) {
                const args = [];
                let { execPath } = process;
+               let jenkinsReporter = resolveModule('mocha-jenkins-reporter');

                // add nyc
                if (cover) {
@@ -178,7 +179,15 @@ module.exports = (opts) => {
                                '--reporter=html',
                                '--reporter=json',
                                '--reporter=text',
-                               '--reporter=text-summary',
+                               '--reporter=text-summary'
+                       );
+                       if (jenkinsReporter) {
+                               args.push('--reporter=' + path.relative(
+                                       resolveModule('istanbul-reports', resolveModule('nyc')),
+                                       jenkinsReporter
+                               ));
+                       }
+                       args.push(
                                '--require', path.resolve(__dirname, '../test-transpile.js'),
                                '--show-process-tree',
                                process.execPath // need to specify node here so that spawn-wrap works
@@ -188,6 +197,8 @@ module.exports = (opts) => {
                        process.env.APPCD_COVERAGE = 1;
                }

+               args.push('--trace-deprecation');
+
                // add mocha
                const mocha = resolveModule('mocha');
                if (!mocha) {
@@ -201,8 +212,7 @@ module.exports = (opts) => {
                        args.push('--inspect-brk');
                }

-               const jenkinsReporter = resolveModule('mocha-jenkins-reporter');
-               if (jenkinsReporter) {
+               if (!cover && jenkinsReporter) {
                        args.push(--reporter=${jenkinsReporter});
                }

@@ -241,13 +251,16 @@ module.exports = (opts) => {
                }
        }

-       function resolveModule(name) {
+       function resolveModule(name, rel) {
                let dir = path.join(appcdGulpNodeModulesPath, name);
                if (fs.existsSync(dir)) {
                        return dir;
                }

                try {
+                       if (rel) {
+                               return require.resolve(name, { paths: [ path.join(rel, 'node_modules') ] });
+                       }
                        return path.dirname(require.resolve(name));
                } catch (e) {
                        return null;
But then we run into a problem where mocha-jenkins-reporter is expecting a mocha runner object and nyc doesn't pass one in.
/Users/chris/appc/appc-daemon/node_modules/mocha-jenkins-reporter/node_modules/mocha/lib/reporters/base.js:252
  runner.on('start', function () {
         ^

TypeError: runner.on is not a function
    at Jenkins.Base (/Users/chris/appc/appc-daemon/node_modules/mocha-jenkins-reporter/node_modules/mocha/lib/reporters/base.js:252:10)
    at new Jenkins (/Users/chris/appc/appc-daemon/node_modules/mocha-jenkins-reporter/lib/jenkins.js:40:8)
    at Object.create (/Users/chris/appc/appc-daemon/node_modules/nyc/node_modules/istanbul-reports/index.js:12:16)
    at /Users/chris/appc/appc-daemon/node_modules/nyc/index.js:451:24
    at Array.forEach (<anonymous>)
    at NYC.report (/Users/chris/appc/appc-daemon/node_modules/nyc/index.js:450:17)
    at report (/Users/chris/appc/appc-daemon/node_modules/nyc/bin/nyc.js:89:7)
    at /Users/chris/appc/appc-daemon/node_modules/nyc/bin/nyc.js:76:25
    at ChildProcess.<anonymous> (/Users/chris/appc/appc-daemon/node_modules/nyc/node_modules/foreground-child/index.js:52:5)
    at emitTwo (events.js:126:13)
I believe that mocha-jenkins-reporter should remain an argument to mocha and not nyc and that we need to figure out why nyc is sniping the \-\-reporter arg to mocha. Maybe it's doing a blind scrap on process.argv?

Comments

  1. Chris Barber 2020-05-07

    Just tested this with Node 12.14.1 and despite \-\-trace\-deprecation being around for years, it still doesn't work with nyc/mocha. I still get the runner.on error. Furthermore, I don't think there's a ton of value in this feature. Calling the deprecated util.isArray() does not show any deprecation messages anyways. So, dropping this feature.

JSON Source