-
Notifications
You must be signed in to change notification settings - Fork 54
[DO NOT MERGE] POC tests at component level #247
Conversation
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.
👍 We would need to document somewhere that we auto run .test.js
files using our testing suite, however you can do your own testing using a test
folder or .spec.js
files.
As a POC looks great, make sure this doesn't get merged or @bbc/psammead-test
will publish though 🙈
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.
This looks great to me, nice & understandable. 👍
Definitely agree on Drew's point though, we'd have to document the Jest behaviour.
@dr3 @bcmn I agree. I think some of this documentation would belong in The current Jest behaviour looks for scripts and packages that have test.js/test.jsx files. It also looks for a
|
This PR should not be merged. |
Resolves #193
Tests at the component level
This PR creates a
psammead-test
component, with Mocha and Chai installed as devDependencies in the component'spackage.json
. The component has atest
script, which runs a test (relevant doc):Another
test
script, which echoes to the console, is added topsammead-brand
.Testing at the parent level
In the parent
package.json
of Psammead, I added a "test:packages" script. It callslerna run test
which will look for a script of name 'test' in each package and will run it (see lerna run docs). I choselerna run test
overlerna exec -- npm test
because it's cleaner - the later will return "Error: no test specified" for all components that lack atest
script.Reviewing this PR
Install Lerna globally if it is not installed
npm install --g lerna
lerna --version
Do
npm test
The usual linting and Jest unit tests will run. This will be followed by the test scripts from
psammead-brand
andpsammead-test
.Implications
New components can be added, with their own testing devDependencies (e.g. mocha/chai in this POC). They might be hooked into the psammead level
npm test
script by being called a consistent name (e.g. "test") and invoked vialerna run test
.However, mandating a consistent script name for component-level tests could prove annoying. Let's say there are several Psammead components have bespoke component-level tests, psammead-component-A, psammead-component-B and psammead-component-C. It might be annoying for the author of psammead-component-C to run
test
scripts from other components if this adds significantly to testing time.