-
Notifications
You must be signed in to change notification settings - Fork 250
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
test: add --ordering
unit tests with chai
#357
Changes from 2 commits
6ed467e
d9f69ab
4996c57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ jobs: | |
test: | ||
name: Test | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: | ||
- '20.10' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
"watch-files": [ | ||
"test/**/*.js", | ||
"lib/**/*.js" | ||
], | ||
"recursive": true, | ||
"file": "./mocha.setup.js", // setup file before everything else loads | ||
"forbid-only": true | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const chai = require("chai"); | ||
const { jestSnapshotPlugin } = require("mocha-chai-jest-snapshot"); | ||
|
||
chai.use(jestSnapshotPlugin()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`command line interface should respect ordering file (format: "\${filepath}") 1`] = ` | ||
Object { | ||
"files": Object { | ||
"private": Object { | ||
"files": Object { | ||
"var": Object { | ||
"files": Object { | ||
"app": Object { | ||
"files": Object { | ||
"file.txt": Object { | ||
"link": "private/var/file.txt", | ||
}, | ||
}, | ||
}, | ||
"file.txt": Object { | ||
"integrity": Object { | ||
"algorithm": "SHA256", | ||
"blockSize": 4194304, | ||
"blocks": Array [ | ||
"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
], | ||
"hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
}, | ||
"size": 11, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"var": Object { | ||
"link": "private/var", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`command line interface should respect ordering file (format: "\${random number} : \${filepath}") 1`] = ` | ||
Object { | ||
"files": Object { | ||
"private": Object { | ||
"files": Object { | ||
"var": Object { | ||
"files": Object { | ||
"app": Object { | ||
"files": Object { | ||
"file.txt": Object { | ||
"link": "private/var/file.txt", | ||
}, | ||
}, | ||
}, | ||
"file.txt": Object { | ||
"integrity": Object { | ||
"algorithm": "SHA256", | ||
"blockSize": 4194304, | ||
"blocks": Array [ | ||
"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
], | ||
"hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
}, | ||
"size": 11, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"var": Object { | ||
"link": "private/var", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`command line interface should respect ordering file (format: ": \${filepath}") 1`] = ` | ||
Object { | ||
"files": Object { | ||
"private": Object { | ||
"files": Object { | ||
"var": Object { | ||
"files": Object { | ||
"app": Object { | ||
"files": Object { | ||
"file.txt": Object { | ||
"link": "private/var/file.txt", | ||
}, | ||
}, | ||
}, | ||
"file.txt": Object { | ||
"integrity": Object { | ||
"algorithm": "SHA256", | ||
"blockSize": 4194304, | ||
"blocks": Array [ | ||
"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
], | ||
"hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
}, | ||
"size": 11, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"var": Object { | ||
"link": "private/var", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`command line interface should unpack static framework with all underlying symlinks unpacked 1`] = ` | ||
Object { | ||
"files": Object { | ||
"private": Object { | ||
"files": Object { | ||
"var": Object { | ||
"files": Object { | ||
"app": Object { | ||
"files": Object { | ||
"file.txt": Object { | ||
"link": "private/var/file.txt", | ||
"unpacked": true, | ||
}, | ||
}, | ||
}, | ||
"file.txt": Object { | ||
"integrity": Object { | ||
"algorithm": "SHA256", | ||
"blockSize": 4194304, | ||
"blocks": Array [ | ||
"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
], | ||
"hash": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
}, | ||
"size": 11, | ||
"unpacked": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"var": Object { | ||
"link": "private/var", | ||
"unpacked": true, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`command line interface should unpack static framework with all underlying symlinks unpacked 2`] = ` | ||
Array [ | ||
Object { | ||
"content": "hello world", | ||
"name": "private/var/app/file.txt", | ||
}, | ||
"private/var/app", | ||
Object { | ||
"content": "hello world", | ||
"name": "private/var/file.txt", | ||
}, | ||
"private/var", | ||
"private", | ||
"var", | ||
] | ||
`; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,8 @@ const compDirs = require('./util/compareDirectories'); | |||||||
const compFileLists = require('./util/compareFileLists'); | ||||||||
const { compFiles } = require('./util/compareFiles'); | ||||||||
const createSymlinkApp = require('./util/createSymlinkApp'); | ||||||||
const { verifySmartUnpack } = require('./util/verifySmartUnpack'); | ||||||||
const { TEST_APPS_DIR } = require('./util/constants'); | ||||||||
|
||||||||
const exec = promisify(childProcess.exec); | ||||||||
|
||||||||
|
@@ -29,7 +31,7 @@ async function assertAsarOutputMatches(args, expectedFilename) { | |||||||
|
||||||||
describe('command line interface', function () { | ||||||||
beforeEach(() => { | ||||||||
rimraf.sync(path.join(__dirname, '..', 'tmp'), fs); | ||||||||
rimraf.sync(TEST_APPS_DIR, fs); | ||||||||
}); | ||||||||
|
||||||||
it('should create archive from directory', async () => { | ||||||||
|
@@ -190,21 +192,53 @@ describe('command line interface', function () { | |||||||
); | ||||||||
}); | ||||||||
it('should unpack static framework with all underlying symlinks unpacked', async () => { | ||||||||
const { tmpPath } = createSymlinkApp('app'); | ||||||||
const { testPath } = await createSymlinkApp('app'); | ||||||||
await execAsar( | ||||||||
`p ${tmpPath} tmp/packthis-with-symlink.asar --unpack *.txt --unpack-dir var --exclude-hidden`, | ||||||||
`p ${testPath} tmp/packthis-with-symlink.asar --unpack *.txt --unpack-dir var --exclude-hidden`, | ||||||||
); | ||||||||
|
||||||||
assert.ok(fs.existsSync('tmp/packthis-with-symlink.asar.unpacked/private/var/file.txt')); | ||||||||
assert.ok(fs.existsSync('tmp/packthis-with-symlink.asar.unpacked/private/var/app/file.txt')); | ||||||||
assert.strictEqual( | ||||||||
fs.readlinkSync('tmp/packthis-with-symlink.asar.unpacked/private/var/app/file.txt'), | ||||||||
path.join('..', 'file.txt'), | ||||||||
await verifySmartUnpack('tmp/packthis-with-symlink.asar'); | ||||||||
}); | ||||||||
it('should respect ordering file (format: "${filepath}")', async () => { | ||||||||
const { testPath, filesOrdering } = await createSymlinkApp('app'); | ||||||||
|
||||||||
const orderingPath = path.join(testPath, '../ordered-app-ordering1.txt'); | ||||||||
const data = filesOrdering.reduce((prev, curr) => { | ||||||||
return `${prev}${curr}\n`; | ||||||||
}, ''); | ||||||||
await fs.writeFile(orderingPath, data); | ||||||||
|
||||||||
await execAsar( | ||||||||
`p ${testPath} tmp/packthis-with-symlink.asar --ordering=${orderingPath} --exclude-hidden`, | ||||||||
); | ||||||||
assert.strictEqual( | ||||||||
fs.readlinkSync('tmp/packthis-with-symlink.asar.unpacked/var'), | ||||||||
path.join('private', 'var'), | ||||||||
await verifySmartUnpack('tmp/packthis-with-symlink.asar'); | ||||||||
}); | ||||||||
it('should respect ordering file (format: ": ${filepath}")', async () => { | ||||||||
const { testPath, filesOrdering } = await createSymlinkApp('app'); | ||||||||
|
||||||||
const orderingPath = path.join(testPath, '../ordered-app-ordering2.txt'); | ||||||||
const data = filesOrdering.reduce((prev, curr) => { | ||||||||
return `${prev}: ${curr}\n`; | ||||||||
}, ''); | ||||||||
await fs.writeFile(orderingPath, data); | ||||||||
|
||||||||
await execAsar( | ||||||||
`p ${testPath} tmp/packthis-with-symlink.asar --ordering=${orderingPath} --exclude-hidden`, | ||||||||
); | ||||||||
await verifySmartUnpack('tmp/packthis-with-symlink.asar'); | ||||||||
}); | ||||||||
it('should respect ordering file (format: "${random number} : ${filepath}")', async () => { | ||||||||
const { testPath, filesOrdering } = await createSymlinkApp('app'); | ||||||||
|
||||||||
const orderingPath = path.join(testPath, '../ordered-app-ordering3.txt'); | ||||||||
const data = filesOrdering.reduce((prev, curr) => { | ||||||||
return `${prev}${Math.floor(Math.random() * 1000)} : ${curr} \n`; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: what happens if the random number has a collision? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing, current logic ignores anything before the Lines 93 to 95 in 9b7ccfe
|
||||||||
}, ''); | ||||||||
await fs.writeFile(orderingPath, data); | ||||||||
|
||||||||
await execAsar( | ||||||||
`p ${testPath} tmp/packthis-with-symlink.asar --ordering=${orderingPath} --exclude-hidden`, | ||||||||
); | ||||||||
assert.ok(fs.existsSync('tmp/packthis-with-symlink.asar.unpacked/var/file.txt')); | ||||||||
await verifySmartUnpack('tmp/packthis-with-symlink.asar'); | ||||||||
}); | ||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('path'); | ||
|
||
// root dir of the repo | ||
const ROOT_PROJECT_DIR = path.resolve(__dirname, '..', '..'); | ||
|
||
// tmp dir we use for test artifacts | ||
const TEST_APPS_DIR = path.join(ROOT_PROJECT_DIR, 'tmp'); | ||
|
||
module.exports = { ROOT_PROJECT_DIR, TEST_APPS_DIR }; |
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.
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 add root-level
./*.js
scripts toprettier:write
as well