-
Notifications
You must be signed in to change notification settings - Fork 819
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
e2e tests for examples #516
base: master
Are you sure you want to change the base?
e2e tests for examples #516
Conversation
package.json
Outdated
@@ -38,6 +38,7 @@ | |||
"test:unit": "jest --config jest.config.js --no-watchman", | |||
"test:ci": "npm run test:unit -- --runInBand", | |||
"test:e2e": "skpm-test", | |||
"test:e2e:examples": "npm run build --prefix __tests__/examples/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe npm run render:once --prefix ...
is better for now? Later on this should probably run with test:e2e
, together with the other e2e tests.
…act-sketchapp into dev/e2e-example-tests
@mathieudutour I've got e2e tests working again, and have the e2e example tests working now too 🙂. Took a while to debug it: I found that importing There's a bit of clean up to do before a merge, but would be ideal to have a review first. I'm using packages that are installed in I'm still running into #515 (in test runner, and in a normal PASS basic
PASS render-context
PASS render-in-wrapped-object
FAIL examples
● examples › should render examples
React SketchApp cannot render into this layer. You may be trying to render into a layer that does not take children. Try rendering into a LayerGroup, Artboard, or Page.
at <anonymous> (../../lib/render.js:23:14)
at <anonymous> (./examples.test.js:72:2)
at <anonymous> (../../node_modules/promise-polyfill/lib/index.js:79:0)
at <anonymous> (../../node_modules/@skpm/timers/timeout.js:18:0)
✕ should render examples Patching
import * as Svg from './Svg'; to import Svg from './Svg'; fixes it and gets the example e2e tests to pass (and |
__tests__/skpm/examples.test.js
Outdated
return sketch.getSelectedDocument() || document; | ||
} | ||
|
||
const examplePages = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot fo this is duplicated in main.js
. Could easily import it from there
@@ -0,0 +1,14 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled it from before the TypeScript refactor. I believe @babel/plugin-transform-modules-commonjs
is needed for @skpm/test-runner
? @skpm/test-runner@0.4.1
has this plugin, but without "noInterop": true
.
Without the .babelrc
file, the tests give this error:
undefined is not an object (evaluating 'module.exports.tests = __skpm_tests__')
@@ -0,0 +1,24 @@ | |||
const path = require('path'); | |||
|
|||
const aliasedModules = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we get this list from the package.json? Just to make sure nothing is missing
@@ -80,7 +81,7 @@ | |||
}, | |||
"devDependencies": { | |||
"@skpm/babel-preset": "^0.2.1", | |||
"@skpm/test-runner": "^0.4.1", | |||
"@skpm/test-runner": "^0.3.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum that's unfortunate. I'll try to see what's up
@@ -30,13 +30,15 @@ | |||
"docs:watch": "npm run docs:prepare && gitbook serve", | |||
"docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch https://github.com/airbnb/react-sketchapp gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push https://github.com/airbnb/react-sketchapp gh-pages --force", | |||
"lint-staged": "lint-staged", | |||
"prepublishOnly": "npm run clean && npm run test:ci && npm run build", | |||
"prepublishOnly": "npm run clean && npm run test:ci && npm run install:e2e && npm run build", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run install:e2e
triggers the __tests__/examples
postinstall
script. Not sure if this should be left in, it'll fail the prepublish script if the examples skpm-build
fails, but not sure if it'll work in CI.
...config.resolve, | ||
alias: { | ||
...config.resolve.alias, | ||
'react-sketchapp': path.resolve(__dirname, '../../lib'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that @skpm/test-runner
needs the commonjs build, and doesn't work with the ES build, strange.
This PR introduces a new e2e test folder that runs the code from all examples at once.
To avoid instantiating each folder's npm packages, I'm installing every npm package that is needed for specific examples, and aliasing them with Webpack, e.g.
chroma-js
, etc. This does currently mean that apostinstall
script to install the packages in__tests__/examples
is required though.npm run test:e2e
appears to be broken since the TypeScript refactor (or later maybe), maybe noncommonjs
modules are being used somewhere. Importingyoga-layout-prebuilt
crashesskpm-test
, but that appears to be usingcommonjs
though.So for now, I'm creating a monolithic test example that is added to the test pipeline with
npm run build --prefix __tests__/examples/
, and can be manually run in Sketch GUI (orskpm-build --run
), or will error out if there is a build breaking issue.This should make it easy to test all examples with a single command.
This PR could be used later on to generate
png
s from all the examples to do a pixel diff test, which would help a lot with the platform bridge refactor, and help out with alignment with React Native, and act as a benchmark for other React renderers to test implementation 🚀. This is something I noticed was mentioned in the React Primitives RFC (using Happo for cross-platform visual regression testing).TODO
skpm-test
and use that instead for the examples testfixes #363