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

ES Bind Operator Throws SyntaxError When Test Failing #881

Closed
ghost opened this issue May 26, 2016 · 6 comments
Closed

ES Bind Operator Throws SyntaxError When Test Failing #881

ghost opened this issue May 26, 2016 · 6 comments
Labels
bug current functionality does not work as desired

Comments

@ghost
Copy link

ghost commented May 26, 2016

Description

I was trying to use the ES bind operator in my test files.
If I transpile the code in the Babel REPL and try it with the resulting ES5 code all is working fine so I think it must be something with AVAs or power-asserts internal transpilation.
After that I tried to make a reproduction and noticed that the SyntaxError is only there if the test fails.

Test Source

import test from 'ava'
import validate from './validate.js'

test('should be a function', t => {
    t.is(typeof validate, 'function')
})

test('should wrap a value in a validation object', t => {
    t.deepEqual(true::validate('foo'), {
        valid: true,
        value: true,
        name: 'bar'
    }, 'boolean')
})

validate.js:

function validate(name) {
    return {
        name,
        valid: true,
        value: this
    }
}

export default validate

Error Message & Stack Trace

> ava


 ⠏ required › should be a function

   1 passed
   1 failed/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:945
  throw err;
  ^

SyntaxError: Unexpected token (1:16)
    at Parser.pp.raise (/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:943:13)
    at Parser.pp.unexpected (/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:1503:8)
    at Parser.pp.expect (/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:1497:26)
    at Parser.pp.parseExprList (/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:643:12)
    at Parser.pp.parseSubscripts (/Users/konstantinpschera/Development/Projects/feed/validation/node_modules/acorn/dist/acorn.js:240:29)
npm ERR! Test failed.  See above for more details.

Config

package.json:

{
  "ava": {
    "require": [
      "babel-register"
    ],
    "failFast": true,
    "babel": "inherit"
  }
}

.babelrc:

{
    "presets": ["es2015", "stage-0"]
}

Command-Line Arguments

ava

Relevant Links

Environment

Mac OSX El Capitan (Version: 10.11.5 (15F34))
darwin 15.5.0
NPM v3.9.3
Node.js v6.2.0
AVA v0.15.1
@sindresorhus
Copy link
Member

@twada Is there any way power-assert can gracefully handle failures like this? Instead of hard failing, it would just not decorate the output, and include a message on why. That way it's still usable.

@sindresorhus sindresorhus added the bug current functionality does not work as desired label May 26, 2016
@twada
Copy link
Contributor

twada commented May 26, 2016

@sindresorhus I'm going to ship new power-assert-runtime soon. It'll fix problems like this entirely.

twada added a commit to twada/power-assert-runtime that referenced this issue May 29, 2016
@sotojuan
Copy link
Contributor

Did this fix the issue? Issue creator deleted his account.

@twada
Copy link
Contributor

twada commented Jul 21, 2016

Will be fixed when #903 is released.

@adjavaherian
Copy link

adjavaherian commented Jul 21, 2016

Just noticed what might be a related issue while testing a React component with Enzyme and Ava's native assertions.

Below, CustomOption is a child component, and I expect wrapper.contains to return true or false:

test('renders children when passed in', t => {
    const wrapper = shallow(
        <Select>
            <CustomOption />
        </Select>
    );
    t.true(wrapper.contains(<CustomOption />));
});

But I end up with this and NPM bails out when the watcher returns 1:

SyntaxError: Unexpected token (1:24)
    at Parser.pp.raise (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:923:13)
    at Parser.pp.unexpected (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:1490:8)
    at Parser.pp.parseExprAtom (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:333:12)
    at Parser.parseExprAtom (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn-es7-plugin/acorn-es7-plugin.js:136:30)
    at Parser.pp.parseExprSubscripts (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:228:19)
    at Parser.pp.parseMaybeUnary (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:207:17)
    at Parser.pp.parseExprOps (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:154:19)
    at Parser.pp.parseMaybeConditional (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:136:19)
    at Parser.pp.parseMaybeAssign (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:112:19)
    at Parser.pp.parseExprList (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:660:23)
    at Parser.pp.parseSubscripts (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:252:29)
    at Parser.pp.parseExprSubscripts (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:231:15)
    at Parser.pp.parseMaybeUnary (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:207:17)
    at Parser.pp.parseExprOps (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:154:19)
    at Parser.pp.parseMaybeConditional (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:136:19)
    at Parser.pp.parseMaybeAssign (/Users/Amir/Desktop/Nestio/pam/node_modules/acorn/dist/acorn.js:112:19)

Conversely, the following is fine.

test('renders children when passed in', t => {
    const wrapper = shallow(
        <Select>
            <CustomOption />
        </Select>
    );

    const truthy = wrapper.contains(<CustomOption />);
    t.true(truthy);
});

CLI

CONFIG=$(pwd)/webpack/webpack.test.config.js BABEL_DISABLE_CACHE=1 NODE_ENV=ava ava "--watch"

Relevant Links

https://github.com/istarkov/babel-plugin-webpack-loaders

ENV

Ava 0.15.2
node 4.4.5

@novemberborn
Copy link
Member

I'm assuming this has been fixed, since #903 was merged.

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
Projects
None yet
Development

No branches or pull requests

5 participants