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

Idea: Simple test runner #32

Open
andywer opened this issue Aug 30, 2018 · 1 comment
Open

Idea: Simple test runner #32

andywer opened this issue Aug 30, 2018 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@andywer
Copy link
Member

andywer commented Aug 30, 2018

Right now we leave it to the user to use the test runner they already have for running the shutter tests.
The downside is that the resulting test code does usually does not look 100% smooth and requires us to document usage of shutter with any major test runner.

An alternative might be to add some really basic test runner functionality to the shutter CLI.

It might sound like re-inventing the wheel at first, but it does make some sense, because the use case and they kind of test you write for shutter is rather different to unit and integration test code.

How it could look like

// src/components/button/button.shutter.test.jsx

import { addFile, configure } from '@shutter/react'
import Button from './button'
import FancyIcon from '../icons/fancy'
import ThemeProvider from '../theme/provider'

const ThemeAProvider = ({ children }) => (
  <ThemeProvider theme='A'>
    {children}
  </ThemeProvider>
)

export default {
  'Just text': {
    'Default button': <Button>Click me!</Button>,
    'Primary button': <Button primary>Primary button</Button>,
  },
  'With icon': {
    'Default button': <Button><FancyIcon /> Click me!</Button>,
    'Primary button': <Button primary><FancyIcon /> Primary button</Button>,
  },
  'Themed': {
    'Theme A': configure({ decorate: ThemeAProvider })(
      <Button>Theme A</Button>
    )
  }
}
// shutter.config.json5 or as "shutter" property in package.json
{
  files: {
    '/styles.css': 'build/styles.css'
  },
  head: [
    <link rel='stylesheet' href='/styles.css' />
  ]
}

Running the tests:

$ npx shutter test

Zero config:

The test runner will check if there is a babel config or tsconfig.json and load @babel/register, babel-core or ts-node, so cutting edge code and JSX will work without further ado.

Still unsolved

What about webpack setups with custom loaders (CSS modules or worker loader, for instance)?!

To be fair, that's an issue as of now, anyway...

@andywer andywer added help wanted Extra attention is needed question Further information is requested labels Aug 30, 2018
@andywer
Copy link
Member Author

andywer commented Sep 7, 2018

Alternative test syntax

The export default object is rather hard to read. This might be more intuitive to use:

import { configure, snapshot, test } from '@shutter/react'
import ThemeProvider from '../theme/provider'

const ThemeAProvider = ({ children }) => (
  <ThemeProvider theme='A'>
    {children}
  </ThemeProvider>
)

// Config object could also passed to `component()` or `snapshot()` as additional parameter
configure({
  decorate: ThemeAProvider
})

test('Button', [
  snapshot('default', <Button>Click me</Button>),
  snapshot('primary', <Button primary>Click me</Button>)
])

Edit: Changed component() to test() as you can use the core package to test whole static pages, not only components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant