question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser recipe doesn't work with default AVA install

See original GitHub issue

@sindresorhus You asked me (https://github.com/avajs/ava/pull/1054#discussion_r81580347) to change from require to import in the browser recipe. Foolishly I didn’t check after I changed it but it doesn’t actually work on a default install because modules that are required by AVA aren’t transpiled.

To fix it we would need to also require the babel bits:

npm install --save-dev babel-register babel-plugin-transform-es2015-modules-commonjs

and require the following settings in package.json:

"ava": {
  "require": [
    "babel-register",
    "./test/helpers/setup-browser-env.js"
  ]
},
"babel": {
  "plugins": ["transform-es2015-modules-commonjs"]
},

Which seems like quite a lot for one little helper.


Do you want me to update the recipe with these requirements?

Or should I revert

import browserEnv from 'browser-env';
browserEnv();

to

require('browser-env')()

so they aren’t necessary?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sindresorhuscommented, Jan 16, 2017

Right. It will work in the next release though, as AVA now transpiles helper files too. So I think we can just keep this issue open until the next release and not do anything.

1reaction
OmgImAlexiscommented, Jul 15, 2017

@sindresorhus this example still doesn’t work as it throws an error about importing.

➜  SickRage git:(develop) ✗ ava test
/Users/xo/code/SickRage/test/helpers/setup-browser-env.js:1
(function (exports, require, module, __filename, __dirname) { import browserEnv from 'browser-env';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Array.forEach (native)
    at Object.<anonymous> (/Users/xo/code/SickRage/node_modules/ava/lib/test-worker.js:35:22)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

  1 exception

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

test/helpers/setup-browser-env.js

import browserEnv from 'browser-env';

browserEnv();
import test from 'ava';

test/index.js

test('Insert to DOM', t => {
    const div = document.createElement('div');
    document.body.appendChild(div);

    t.is(document.querySelector('div'), div);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I enable Java in my web browser?
Java is not enabled in the web browser. If Java is already installed but applets do not work, you need to enable Java...
Read more >
Troubleshooting tips for running Java
Download and Install Java · Try the offline installer package (Windows only) · Uninstall any non-working Java installations · Temporarily turn off firewall...
Read more >
Java is not working in Internet Explorer after I just installed Java
Workaround · Open IE browser · Click on Tools tab. Note: If the Tools tab is not visible in Tools bar, right click...
Read more >
How do I enable Java through the Control Panel?
In the Java Control Panel, click the Security tab. · Select the option Enable Java content in the browser. · Click Apply and...
Read more >
How to activate Java in the browser
It is recommended you update Java before allowing the app to run. Click Update and download the latest Java version. If you don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found