Skip to content

Setting up tests with preact-cli project #52

@01binary

Description

@01binary

Is there an article on setting this up with preact-cli created project? I have no doubt you are very busy so I will keep hacking, but if you know what's happening please let me know.

TL;DR: yarn && yarn test on my branch

$ mocha --recursive --require babel-polyfill --compilers js:babel-register

Gets me:

SyntaxError: d:/Desktop/ultravest-assistant/test/state/Component.tests.js: Unexpected token (12:9)
  10 |  it('any test that uses JSX', () => {
  11 |          // following taken from preact-jsx-chai readme
> 12 |          expect(<div id="1">a</div>).to.eql(<div id="1">a</div>);
     |                 ^
  13 |  });
  14 | });

I have some other tests that don't use JSX and work. I ended up putting babel "env" preset into my package.json because I go to extreme lengths to keep my package root clean, but doing the same with .babelrc didn't make any difference. My package is customized from what preact-cli did, in an attempt to get tests to work:

{
  "name": "ultravest-assistant",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "lint": "eslint src",
    "test": "mocha --recursive --require babel-polyfill --compilers js:babel-register",
    "start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
    "build": "lint && preact build",
    "serve": "preact build && preact serve",
    "dev": "preact watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "eslintConfig": {
    "extends": "eslint-config-synacor"
  },
  "babel": {
    "presets": [ "env" ]
  },
  "devDependencies": {
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.0",
    "babel-register": "^6.26.0",
    "chai": "^4.1.2",
    "eslint": "^4.6.1",
    "eslint-config-synacor": "^1.1.1",
    "if-env": "^1.0.0",
    "mocha": "^3.5.0",
    "preact-cli": "^1.4.1",
    "sass-lint": "^1.11.1"
  },
  "dependencies": {
    "node-sass": "^4.5.3",
    "preact": "^8.2.5",
    "preact-compat": "^3.17.0",
    "preact-jsx-chai": "^2.2.1",
    "react": "npm:preact-compat",
    "recompose": "^0.25.0",
    "sass-loader": "^6.0.6"
  }
}

I am confused because error message indicates it's getting transpiled through babylon but it's still unhappy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions