-
Notifications
You must be signed in to change notification settings - Fork 251
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: adding chai+snapshot support. adding --ordering
unit tests
#357
base: main
Are you sure you want to change the base?
Conversation
…pp with new `ordering` file unit tests
…ing it needs to be fixed but currently the fixture is flaky and warrants a separate investigation ¯\_(ツ)_/¯
.mocharc.js
Outdated
"recursive": true, | ||
"file": "./mocha.setup.js", // setup file before everything else loads | ||
"forbid-only": true | ||
} |
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 to prettier:write
as well
package.json
Outdated
@@ -44,10 +45,12 @@ | |||
"devDependencies": { | |||
"@types/minimatch": "^3.0.5", | |||
"@types/node": "^12.0.0", | |||
"chai": "^4", |
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.
nit: we usually use caret ranges with a full version number, so that'd be like ^4.5.0
const privateVarPath = path.join(tmpPath, 'private', 'var'); | ||
const varPath = path.join(tmpPath, 'var'); | ||
module.exports = async (testName, additionalFiles = {}) => { | ||
const outDir = (testName || 'app') + Math.floor(Math.random() * 100); |
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.
Can we just use fs.mkdtemp
here instead?
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.
We could, but the reason why I did it this way was that all other test artifacts/fixtures are outputted to ${ROOT_PROJECT_DIR}/tmp
, so I figured I would keep it consistent. It has the added benefit of the tmp
dir is cleaned before each individual test and being able to debug a test failure from an easy location.
Happy to translate the logic to mkdtemp
if preferred!
|
||
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 comment
The 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 comment
The 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
if (line.includes(':')) { | |
line = line.split(':').pop()!; | |
} |
…itional files to verify that "ordering" is successfully applied
99608e5
to
4996c57
Compare
(Proposing this as an alternative to migrating to jest?)
Note: This was test-only changes, but I was encouraged to add jsdoc to
ordering
, so I'm not sure iftest:
is the correct tag now.Following up from a convo and the jest PR, this provides interim support for snapshot tests while still leveraging
mocha
andelectron-mocha
. This PR adds dynamically generatedordering.txt
files for test coverage of current ordering logicAdds 3 unit tests to cover ordering.txt files w/:
filepath
: filepath
random-number : filepath
Functionally, this PR adds:
test.yaml
->fail-fast: false
allows the matrix jobs to continue even when one fails. This will allow verifying asar behavior across each node version before the overall test is marked as a failure.verifySmartUnpack
helper function that does the following:verifyHeader
- parses out unstable properties ("offset" varies per build machine?), converts all paths (e.g.link
) to system independent strings, and then stores it as a snapshotverifyFileTree
- Traverses a directory and snapshots the tree hierarchy and plain text files (also used for unpacked dir snapshots)createSymlinkedApp
- Creates a new app at runtime from the app template, adds folders, symlinks, and allows you to pass inadditionalFiles
that you can use to customize each app's directoryWith
verifySmartUnpack
, the header snapshot allows finer granularity of what is happening under the hood, especially with regards to symlinks and integrity calculations. Example respective snapshots excerpts below:Then the "walk" snapshot functionality allows all these lines to become just included in
verifySmartUnpack('tmp/packthis-unpack-subdir-cli.asar')
asar/test/cli-spec.js
Lines 182 to 185 in 121efeb