Clean up uses of deprecated API's in node core (#51431) (#52192)

Ensure no deprecated Node.js core API's are used in Kibana. This is
achieved by throwing an error in either development mode or in CI if one
of the deprecated API's is called, and as such, new PR's should no
longer be able to be merged if they use deprecated API's.

Some of these API's (like the `Buffer` constructor`) is a security risk.
This commit is contained in:
Thomas Watson 2019-12-04 18:18:38 +01:00 committed by GitHub
parent dfc0612f26
commit 995a914f63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 638 additions and 207 deletions

View file

@ -17,14 +17,12 @@
* under the License.
*/
import bluebird, {
fromNode,
promisify,
} from 'bluebird';
import bluebird, { promisify } from 'bluebird';
import Handlebars from 'handlebars';
import fs from 'fs';
import path from 'path';
import imageDiff from 'image-diff';
import { PNG } from 'pngjs';
import pixelmatch from 'pixelmatch';
import moment from 'moment';
import SimpleGit from 'simple-git';
@ -110,17 +108,23 @@ async function compareScreenshots() {
screenshot
);
// Diff the images asynchronously.
const diffResult = await fromNode((cb) => {
imageDiff.getFullResult({
actualImage: sessionImagePath,
expectedImage: baselineImagePath,
diffImage: diffImagePath,
shadow: true,
}, cb);
});
const sessionImage = PNG.sync.read(await fs.promises.readFile(sessionImagePath));
const baselineImage = PNG.sync.read(await fs.promises.readFile(baselineImagePath));
const { width, height } = sessionImage;
const diff = new PNG({ width, height });
const change = diffResult.percentage;
const numDiffPixels = pixelmatch(
sessionImage.data,
baselineImage.data,
diff.data,
width,
height,
{ threshold: 0 }
);
await fs.promises.writeFile(diffImagePath, PNG.sync.write(diff));
const change = numDiffPixels / (width * height);
const changePercentage = (change * 100).toFixed(2);
console.log(`(${changePercentage}%) ${screenshot}`);
comparison.percentage = changePercentage;