asar/test/util/compareFiles.js

35 строки
1.1 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

'use strict';
2019-02-19 00:22:45 +03:00
const assert = require('assert');
const fs = require('../../lib/wrapped-fs').default;
2016-12-04 20:59:34 +03:00
module.exports = async function (actualFilePath, expectedFilePath) {
if (process.env.ELECTRON_ASAR_SPEC_UPDATE) {
await fs.writeFile(expectedFilePath, await fs.readFile(actualFilePath));
}
const [actualFileContent, expectedFileContent] = await Promise.all([
fs.readFile(actualFilePath, 'utf8'),
fs.readFile(expectedFilePath, 'utf8'),
]);
assert.strictEqual(actualFileContent, expectedFileContent);
const [actualIsSymlink, expectedIsSymlink] = [
isSymbolicLinkSync(actualFilePath),
isSymbolicLinkSync(expectedFilePath),
];
assert.strictEqual(actualIsSymlink, expectedIsSymlink);
if (actualIsSymlink && expectedIsSymlink) {
const [actualSymlinkPointer, expectedSymlinkPointer] = [
fs.readlinkSync(actualFilePath),
fs.readlinkSync(expectedFilePath),
];
assert.strictEqual(actualSymlinkPointer, expectedSymlinkPointer);
}
};
function isSymbolicLinkSync(path) {
const stats = fs.lstatSync(path);
return stats.isSymbolicLink();
2016-12-29 00:45:36 +03:00
}