Skip to content

Commit

Permalink
test: don't run symlink tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Jan 11, 2025
1 parent a7c67f7 commit 1b93615
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
73 changes: 41 additions & 32 deletions test/api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const rimraf = require('rimraf');
const asar = require('..');
const compDirs = require('./util/compareDirectories');
const compFileLists = require('./util/compareFileLists');
const compFiles = require('./util/compareFiles');
const { compFiles, isSymbolicLinkSync } = require('./util/compareFiles');
const transform = require('./util/transformStream');

async function assertPackageListEquals(actualList, expectedFilename) {
Expand Down Expand Up @@ -107,38 +107,47 @@ describe('api', function () {
asar.extractAll('test/input/extractthis-unpack-dir.asar', 'tmp/extractthis-unpack-dir-api/');
return compDirs('tmp/extractthis-unpack-dir-api/', 'test/expected/extractthis');
});
it('should extract an archive with symlink', async () => {
await asar.createPackageWithOptions(
'test/input/packthis-with-symlink/',
'tmp/packthis-with-symlink.asar',
{ dot: false },
);
asar.extractAll('tmp/packthis-with-symlink.asar', 'tmp/packthis-with-symlink/');
return compFiles(
'tmp/packthis-with-symlink/real.txt',
'test/input/packthis-with-symlink/real.txt',
);
});
it('should extract an archive with symlink having the same prefix', async () => {
await asar.createPackageWithOptions(
'test/input/packthis-with-symlink-same-prefix/',
'tmp/packthis-with-symlink-same-prefix.asar',
{ dot: false },
);
asar.extractAll(
'tmp/packthis-with-symlink-same-prefix.asar',
'tmp/packthis-with-symlink-same-prefix/',
);
return compFiles(
'tmp/packthis-with-symlink-same-prefix/real.txt',
'test/input/packthis-with-symlink-same-prefix/real.txt',
);
});
it('should not extract an archive with a bad symlink', async () => {
assert.throws(() => {
asar.extractAll('test/input/bad-symlink.asar', 'tmp/bad-symlink/');

// We don't extract symlinks on Windows, so skip these tests
if (os.platform() !== 'win32') {
it('should extract an archive with symlink', async () => {
assert.strictEqual(isSymbolicLinkSync('test/input/packthis-with-symlink/real.txt'), true);
await asar.createPackageWithOptions(
'test/input/packthis-with-symlink/',
'tmp/packthis-with-symlink.asar',
{ dot: false },
);
asar.extractAll('tmp/packthis-with-symlink.asar', 'tmp/packthis-with-symlink/');
return compFiles(
'tmp/packthis-with-symlink/real.txt',
'test/input/packthis-with-symlink/real.txt',
);
});
});
it('should extract an archive with symlink having the same prefix', async () => {
assert.strictEqual(
isSymbolicLinkSync('test/input/packthis-with-symlink-same-prefix/real.txt'),
true,
);
await asar.createPackageWithOptions(
'test/input/packthis-with-symlink-same-prefix/',
'tmp/packthis-with-symlink-same-prefix.asar',
{ dot: false },
);
asar.extractAll(
'tmp/packthis-with-symlink-same-prefix.asar',
'tmp/packthis-with-symlink-same-prefix/',
);
return compFiles(
'tmp/packthis-with-symlink-same-prefix/real.txt',
'test/input/packthis-with-symlink-same-prefix/real.txt',
);
});
it('should not extract an archive with a bad symlink', async () => {
assert.throws(() => {
asar.extractAll('test/input/bad-symlink.asar', 'tmp/bad-symlink/');
});
});
}
it('should handle multibyte characters in paths', async () => {
await asar.createPackageWithOptions(
'test/input/packthis-unicode-path/',
Expand Down
2 changes: 1 addition & 1 deletion test/cli-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const rimraf = require('rimraf');

const compDirs = require('./util/compareDirectories');
const compFileLists = require('./util/compareFileLists');
const compFiles = require('./util/compareFiles');
const { compFiles } = require('./util/compareFiles');
const createSymlinkApp = require('./util/createSymlinkApp');

const exec = promisify(childProcess.exec);
Expand Down
6 changes: 4 additions & 2 deletions test/util/compareFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');
const fs = require('../../lib/wrapped-fs').default;

module.exports = async function (actualFilePath, expectedFilePath) {
async function compFiles(actualFilePath, expectedFilePath) {
if (process.env.ELECTRON_ASAR_SPEC_UPDATE) {
await fs.writeFile(expectedFilePath, await fs.readFile(actualFilePath));
}
Expand All @@ -26,9 +26,11 @@ module.exports = async function (actualFilePath, expectedFilePath) {
];
assert.strictEqual(actualSymlinkPointer, expectedSymlinkPointer);
}
};
}

function isSymbolicLinkSync(path) {
const stats = fs.lstatSync(path);
return stats.isSymbolicLink();
}

module.exports = { compFiles, isSymbolicLinkSync };

0 comments on commit 1b93615

Please sign in to comment.