bigtest icon indicating copy to clipboard operation
bigtest copied to clipboard

JSX not supported in .js test bundles

Open cowboyd opened this issue 4 years ago • 7 comments

I'm attempting to write a React component harness for BigTest in order to test the @stripes/components design system. My idea is that there will be a Mount() step that takes some JSX and then sends a message to the app that mounts that component:

import { test } from 'bigtest';
import { KeyValue as Interactor } from '@stripes/testing';
import { Mount } from './helpers';

export default test("KeyValue")
  .step(Mount((React, KeyValue) =>
    (<KeyValue
       data-test-foo="bar"
       label="Label"
       value="Value"
       subValue="subValue"
     />), "KeyValue"))
  .assertion(KeyValueInteractor("Label").exists());

This compiles into a function which, when passed to the render app takes the value of React and the KeyValue component and then returns the corresponding react component.

However, our current bundler doesn't support a custom babel config, so this is a syntax error. We need a way to extend the babel config in our bundler. If we can already do this, then we should document it.

See this repo for details:

https://github.com/cowboyd/stripes-components/tree/integrate-bigtest

cowboyd avatar Nov 17 '20 22:11 cowboyd

@cowboyd try .jsx

taras avatar Nov 17 '20 22:11 taras

@taras sadly, that doesn't seem to work:

[manifest builder] build error:
Unexpected token (Note that you need plugins to import files that are not JavaScript)

cowboyd avatar Nov 18 '20 15:11 cowboyd

@cowboyd does this Mount function exist yet or is there a branch that is causing the error with the code in your previous comment?

dagda1 avatar Nov 25 '20 14:11 dagda1

@cowboyd looking at the source code for @rollup/plugin-babel, it does search for a babelrc by default although if it finds a babel.config.js, that takes precedence.

It is a long time since I used babel. If possible, could you help me get a failing example?

dagda1 avatar Nov 25 '20 17:11 dagda1

@dagda1 I pushed the mount helper to this branch (I'd forgotten to check it in)

cowboyd avatar Nov 25 '20 18:11 cowboyd

@cowboyd many thanks. That is a big help

dagda1 avatar Nov 25 '20 19:11 dagda1

@cowboyd I made progress on this.

The @rollup/plugin-babel does pick up a babel.config.js or a babelrc automatically and merges it with the config we currently have in the rollup config.

We currently have the rollup commonjs plugin in the wrong order in the plugins rollup config. I've created #689 to correct this.

dagda1 avatar Nov 26 '20 00:11 dagda1