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 does not transpile helpers! #1319

Closed
grvcoelho opened this issue Mar 23, 2017 · 4 comments
Closed

Ava does not transpile helpers! #1319

grvcoelho opened this issue Mar 23, 2017 · 4 comments
Labels
bug current functionality does not work as desired scope:globbing

Comments

@grvcoelho
Copy link

Description

Ava should transpile helper files without requiring babel-register or any such a thing.

If the test files are inside a test folder, this works.

However: if the files are inside another folder (e.g: my-tests instead of test) or are inside a subfolder (e.g: test/unit) this does not work.

TLDR: If tests are inside a subfolder of test directory, ava DOES NOT TRANSPILE helper files

Test Source

/* FILE: test/unit/helpers/index.js */
import Promise from 'bluebird'

export const delay = (n) => Promise.delay(n)

/* ============================== */

/* FILE: test/unit/index.js */
import test from 'ava'
import { delay } from './helpers'

test('should return true', async (t) => {
  console.log('starting ===>', Date.now())
  await delay(2000)
  console.log('finishing ==>', Date.now())

  return true
})

Error Message & Stack Trace

~/H/l/ava (master) [n] ⋊> ./node_modules/.bin/ava test
/Users/grvcoelho/Hyperspace/labs/ava/test/unit/helpers/index.js:1
(function (exports, require, module, __filename, __dirname) { import Promise from 'bluebird'
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Module._extensions..js (module.js:580:10)
    at extensions.(anonymous function) (/Users/grvcoelho/Hyperspace/labs/ava/node_modules/require-precompiled/index.js:16:3)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/grvcoelho/Hyperspace/labs/ava/node_modules/ava/lib/process-adapter.js:105:4)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/grvcoelho/Hyperspace/labs/ava/test/unit/request.js:3:1)
    at Module._compile (module.js:571:32)
    at extensions.(anonymous function) (/Users/grvcoelho/Hyperspace/labs/ava/node_modules/require-precompiled/index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/grvcoelho/Hyperspace/labs/ava/node_modules/ava/lib/process-adapter.js:105:4)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/grvcoelho/Hyperspace/labs/ava/node_modules/ava/lib/test-worker.js:33:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

  1 exception

  ✖ test/unit/request.js exited with a non-zero exit code: 1

Config

No configuration, which means no babel-register or such things

{
  "ava": {
  ...
  }
}

Command-Line Arguments

ava

Relevant Links

Repo with detailed instructions to reproduce the behavior: https://github.com/wasting-light/avajs-bug-report-x89

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: v7.4.0
OS: darwin 16.4.0
Ava: 0.18.2
npm: 4.0.5
@grvcoelho
Copy link
Author

I think I might have discovered the problem:

We have the following code in this line:

const defaultHelperPatterns = () => [

const defaultHelperPatterns = () => [
	'**/__tests__/helpers/**/*.js',
	'**/__tests__/**/_*.js',
	'**/test/helpers/**/*.js',
	'**/test/**/_*.js'
];

This globs do not cover a case like test/unit/helpers/index.js. If this is the problem it could be easily fixed by adding a **/test/**/helpers/**/*.js glob, like this:

const defaultHelperPatterns = () => [
	'**/__tests__/**/helpers/**/*.js',
	'**/__tests__/**/_*.js',
	'**/test/**/helpers/**/*.js',
	'**/test/**/_*.js'
];

Am I thinking this right?

@grvcoelho
Copy link
Author

Just tested, and my previous comment works! Gonna open the PR :)

@novemberborn novemberborn added the bug current functionality does not work as desired label Aug 5, 2017
@novemberborn
Copy link
Member

I think we should solve this by improving how test files are selected, and letting users specify patterns that match helpers. See #1228 (comment).

@novemberborn novemberborn added this to the 1.0 milestone Sep 3, 2017
eloquence added a commit to eloquence/lib.reviews that referenced this issue Nov 5, 2017
With the new Node LTS as our baseline we don't really have to
do extra transpilation. ava still does its own but it does so
inconsistently ( avajs/ava#1319 ),
so we've switched back from import to require(). Indeed ava
might get an option to turn off transpilation altogether
( avajs/ava#1556 ), which we
may end up using if it doesn't come with bad tradeoffs.
novemberborn pushed a commit that referenced this issue Jan 24, 2018
@novemberborn
Copy link
Member

See #2105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired scope:globbing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants