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
Refactor system tests #4755
Refactor system tests #4755
Conversation
3599722
to
90056e9
Compare
90056e9
to
5b2dda5
Compare
lib/__tests__/standalone-fix.test.js
Outdated
const standalone = require('../standalone'); | ||
|
||
const copyFile = promisify(fs.copyFile); | ||
const readFile = promisify(fs.readFile); |
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 believe it's possible to do in Node.js 10+:
const { copyFile } = require('fs').promises;
or
const { copyFile } = require('fs/promises');
https://nodejs.org/api/fs.html#fs_fs_promises_api
https://nodejs.org/api/fs.html#fs_fspromises_copyfile_src_dest_mode
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.
That's odd. I originally wrote it using the promise API but refactored it after the node/no-unsupported-features
ESLint plugin warned against using it. I'll take another look because it appears to be a stable API in node@10.
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.
Linter plugin false positive mysticatea/eslint-plugin-node#174
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'll use the API and disable the ESLint warning for now.
system-tests/systemTestUtils.js
Outdated
const replaceBackslashes = require('../lib/testUtils/replaceBackslashes'); | ||
|
||
const copyFile = promisify(fs.copyFile); | ||
const readFile = promisify(fs.readFile); |
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.
Same as comment above. promisify
is not needed here.
system-tests/systemTestUtils.js
Outdated
results: results.map(({ _postcssResult, ...rest }) => { | ||
delete rest.source; | ||
|
||
return rest; | ||
}), | ||
output, | ||
...rest, |
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.
For safety let's use different names for rest
, so we're not confused in results
scope what rest
we're dealing with.
Also we can use single way of removing unneeded property:
results: results.map(({ _postcssResult, source, ...rest }) => {
return rest;
}),
Or:
results: results.map((result) => {
delete result.source;
delete result._postcssResult;
return result;
}),
Changes made. |
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.
Good work!
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.
Good stuff.
This lays the foundation for being able to test bundled code against real-world examples, closing #2454 and #3935.
The system tests were designed to:
Somewhere along the line, we muddied the waters. Tests that were not related to real-world cases, didn't use real-world configs, nor snapshotted the results were added. The tests often duplicated specific fixtures from the
__tests__/fixtures
directory into theconfig.json
andstylesheet.css
files of the system tests.This has led to a fragmentation of the tests.
Additionally, the landscape has changed. The original system tests were added before:
I've used this opportunity to update the system tests to reflect this.
In this pull request, I've:
lib/__tests__
, making use of existing fixtures or creating new ones where appropriatereplaceBackSlashes
intotestUtils
, cleaning up the__tests__
directoryreplaceBackSlashes
function fromsystemTestUtils.js
code
andconfig
properties, rather thanfile
andconfigFile
ones, to avoid filesystem access