-
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: migrate to jest
, leverage asar header and unpacked dir snapshots, and get swoll 💪
#355
base: main
Are you sure you want to change the base?
Conversation
…re's variance between node versions)
…ain snapshots when running on different OS's
import { platform } from 'os'; | ||
|
||
test.if = (condition: boolean) => (condition ? test : test.skip); | ||
test.ifWindows = test.if(platform() === 'win32'); |
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.
Very neat, thanks!
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.
Looks generally good! Left a few tiny stylistic things but I think we can ✅ this PR once merge conflicts are fixed
test/setup/jest.global.setup.ts
Outdated
import fs from '../../lib/wrapped-fs'; | ||
|
||
export default () => { | ||
rimraf.sync(path.join(__dirname, '..', '..', 'tmp'), fs); |
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.
This looks a little scary on first read and could maybe use a little comment
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.
Haha yeah, fair point. It was copied from the mocha setup. Will add a comment
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.
Converted it to a constant in new file ./util/constants
with comment on it as to what ROOT_DIR
and TEST_APPS_DIR
are being used for
test/util/transformStream.ts
Outdated
constructor() { | ||
super(); | ||
this._data = ''; | ||
} | ||
|
||
_transform(buf, enc, cb) { | ||
_transform(buf: any, enc: any, cb: () => any) { |
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.
Should we use unknown
here?
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.
Either way works for me. tsc
was just throwing an error when it was converted to .ts
. I'll adjust to unknown
or find a proper type for them
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.
Updated.
Note: new definition is _transform(chunk: any, _encoding: string, cb: TransformCallback)
that directly copies the API from @types/node/stream.d.ts
|
||
const rootDir = path.resolve(__dirname, '..', '..'); | ||
|
||
export const verifySmartUnpack = async (asarPath: string) => { |
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 don't have a strong opinion, I'm just curious - why export const
declarations for these functions but export function
for the ones below?
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.
Yeahhh, I'll tidy that up! Had copied some helper code from electron-builder and hadn't modified those. I'll fix it
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.
Updated all test functions to be export const
. I didn't modify src code even though those are export function
. I personally prefer arrow functions, but am happy to adjust if consistency across src+test is preferred.
…-tests # Conflicts: # test/cli-spec.ts # test/util/createSymlinkApp.js
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 think this needs further consideration before landing, so throwing a "request changes" on just to ensure it doesn't merge before that happens.
The current tests use electron-mocha
to also run the tests inside Electron's main process. With these changes that's no longer true. That's not necessarily a bad thing, but one we consider properly before landing (and would also remove more dependencies).
Probably a good topic to discuss in the next WG meeting, to gather more historical context on why that choice as made originally.
@dsanders11 fantastic callout. I plan to be at the upcoming WG meeting as well. Re: electron-mocha, I believe that |
That ensures that it's testing in a Node-like environment (aka no DOM), but the original testing setup in this repo ran the tests actually inside an Electron main process, which would catch issues that |
… and `electron/main` processes w/ `xvfb-maybe`. Removed `electron-mocha` from devDeps
…-tests # Conflicts: # test/cli-spec.ts # test/util/createSymlinkApp.js
Thank you @dsanders11 for clarifying! I've updated PR to leverage |
Hey folks, I've proposed a different approach that still leverages |
This is a test-only upgrade PR
PR diff line changes may seem large, but they're largely devDeps
yarn.lock
(jest
,ts-jest
, etc @ 2.3k lines) and snapshot files (~1.3k lines). This still runs unit tests in bothnode
andelectron/main
test environments leveragingjest
'stestRunner
functionality 🙂Looking to achieve a few things with this PR
jest
, which will make an even easier transition tovitest
post-node22 upgrade (plug-n-play swap IIRC)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 directoryit.ifWindows = (os.platform() === 'win32') ? test : test.skip
to be used instead of embedding tests within anif
statement (the latter causes snapshots to be deleted on different OS's, but using atest.skip
retains a snapshot)it.ifNotWindows
it.ifNotWindows("some test trying to extra a symlink from an asar", () => { ... })
await
as previously it was doing a strict equals on twoPromises
With
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