Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ava showing random line as error #1604

Closed
OmgImAlexis opened this issue Dec 1, 2017 · 4 comments
Closed

Ava showing random line as error #1604

OmgImAlexis opened this issue Dec 1, 2017 · 4 comments
Labels

Comments

@OmgImAlexis
Copy link

Description

When using ava on my test file the error shown is from a completely different line.

Test Source

const defaults = {
  name: 'queue',
  processEvery: humanInterval('5 seconds'),
  defaultConcurrency: 5,
  maxConcurrency: 0,
  defaultLockLimit: 0,
  lockLimit: 0,
  definitions: {},
  runningJobs: [],
  lockedJobs: [],
  jobQueue: [],
  defaultLockLifetime: TEN_MINUTES,
  sort: {nextRunAt: 1, priority: -1},
  isLockingOnTheFly: false,
  jobsToLock: [],
  indices: {
    disabled: 1,
    lockedAt: 1,
    name: 1,
    nextRunAt: 1,
    priority: -1
  }
};

test.only('return self', t => {
  const definition = new Definition();
  t.true(definition instanceof Definition);
  t.deepEqual(definition.config, defaults);
});

Error Message & Stack Trace

yarn run v1.3.2
$ NODE_ENV=test nyc ava test/definition.js

  1 failed

  return self

  /Users/xo/code/agenda/lib/definition.js:19

   18: //   }
   19: // });
   20:       

  Error thrown in test:

  TypeError {
    message: 'Cannot destructure property `name` of \'undefined\' or \'null\'.',
  }

  new Definition (lib/definition.js:19:29)
  Test.test.only.t [as fn] (test/definition.js:39:22)
  processEmit [as emit] (node_modules/nyc/node_modules/signal-exit/index.js:155:32)
  processEmit [as emit] (node_modules/nyc/node_modules/signal-exit/index.js:155:32)



  The .only() modifier is used in some tests. 1 test was not run
---------------|----------|----------|----------|----------|----------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
---------------|----------|----------|----------|----------|----------------|
All files      |    16.67 |      100 |        0 |    16.67 |                |
 definition.js |    16.67 |      100 |        0 |    16.67 | 23,24,25,26,27 |
---------------|----------|----------|----------|----------|----------------|
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Config

Copy the relevant section from package.json:

N/A

Command-Line Arguments

Copy your npm build scripts or the ava command used:

ava test/definition.js

Relevant Links

This is lib/definition.js.

// // Example
// new Definition({
//   name: 'send email report',
//   priority: 'high',
//   concurrency: 10,
//   data: {
//     to: 'random@example.com'
//   },
//   fn: async ctx => {
//     const {data} = ctx.meta;
//     await emailClient.send({
//       to: data.to,
//       from: 'example@example.com',
//       subject: 'Email Report',
//       body: '...'
//     });
//   }
// });

class Definition {
  constructor({name, priority, concurrency, fn, data}) {
    this.name = name;
    this.priority = priority;
    this.concurrency = concurrency;
    this.fn = fn;
    this.meta.data = data;
  }
}

module.exports = Definition;

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:

Node.js v8.9.1
darwin 16.7.0
npm: 5.5.1
yarn: 1.3.2
ava: 0.24.0
@novemberborn
Copy link
Member

The snippet does correspond to the stack trace: new Definition (lib/definition.js:19:29)

Though the line there seems wrong. Have you tried without nyc? Are there any source maps in play?

@OmgImAlexis
Copy link
Author

Hadn't thought of running it without nyc. Should I report this to nyc's repo?

➜  agenda git:(promise-rewrite) ✗ yarn nyc ava test/definition.js
yarn run v1.3.2
$ /Users/xo/code/agenda/node_modules/.bin/nyc ava test/definition.js

  1 passed
  1 failed

  return self with config

  /Users/xo/code/agenda/lib/definition.js:28

   27:  *  @property {Object} concurrency
   28:  *  @property {Object} data       
   29:  *  @property {Promise} fn The job

  Error thrown in test:

  TypeError {
    message: '"fn" param is required.',
  }

  new Definition (lib/definition.js:28:227)
  Test.t [as fn] (test/definition.js:20:22)
  processEmit [as emit] (node_modules/nyc/node_modules/signal-exit/index.js:155:32)
  processEmit [as emit] (node_modules/nyc/node_modules/signal-exit/index.js:155:32)
---------------|----------|----------|----------|----------|----------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
---------------|----------|----------|----------|----------|----------------|
All files      |       60 |       25 |      100 |       60 |                |
 definition.js |       60 |       25 |      100 |       60 |          36,46 |
---------------|----------|----------|----------|----------|----------------|
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
➜  agenda git:(promise-rewrite) ✗ yarn ava test/definition.js   
yarn run v1.3.2
$ /Users/xo/code/agenda/node_modules/.bin/ava test/definition.js

  1 passed
  1 failed

  return self with config

  /Users/xo/code/agenda/lib/definition.js:34

   33:     if (Object.prototype.toString.call(fn) !== '[object Promise]') {
   34:       throw new TypeError('"fn" param is required.');               
   35:     }                                                               

  Error thrown in test:

  TypeError {
    message: '"fn" param is required.',
  }

  new Definition (lib/definition.js:34:13)
  Test.t [as fn] (test/definition.js:20:22)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@novemberborn
Copy link
Member

Thanks for reporting this upstream, @OmgImAlexis.

@OmgImAlexis
Copy link
Author

OmgImAlexis commented Jan 8, 2021

Looks like versions of node above v14 can use --enable-source-maps to fix this.

istanbuljs/nyc#619 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants