mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: Use expect for assertions (#5581)
Rather than use our own custom expect library, we can use expect from npm [1], which has an API almost identical to the one Puppeteer has, but with more options, better diffing, and is used by many in the community as it's the default assertions library that comes with Jest. It's also thoroughly documented [2]. [1]: https://www.npmjs.com/package/expect [2]: https://jestjs.io/docs/en/expect
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const expect = require('expect');
|
||||
const GoldenUtils = require('./golden-utils');
|
||||
const {FlakinessDashboard} = require('../utils/flakiness-dashboard');
|
||||
const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..');
|
||||
|
||||
@@ -72,6 +74,19 @@ const utils = module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
extendExpectWithToBeGolden: function(goldenDir, outputDir) {
|
||||
expect.extend({
|
||||
toBeGolden: (testScreenshot, goldenFilePath) => {
|
||||
const result = GoldenUtils.compare(goldenDir, outputDir, testScreenshot, goldenFilePath);
|
||||
|
||||
return {
|
||||
message: () => result.message,
|
||||
pass: result.pass
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user