Skip to content

Commit 64c996c

Browse files
committed
update code comments with more context
1 parent a1d4095 commit 64c996c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
// - this exists because I'm not sure how to mock
22
// the dynamic import function, so mocking this instead
3+
// (also, if it _is_ possible to mock the dynamic import,
4+
// there's the risk of altering/breaking the behavior of imports
5+
// across the board - including non-dynamic imports)
6+
//
37
// - also, vitest has a limitation on mocking:
48
// https://vitest.dev/guide/mocking/modules.html#mocking-modules-pitfalls
9+
//
510
// - basically if a function is called by another function in the same file
611
// it can't be mocked. So this was extracted into a separate file
12+
//
13+
// - one thing to note is vitest does the same thing here:
14+
// https://github.com/vitest-dev/vitest/blob/main/test/core/src/dynamic-import.ts
15+
// - and uses that with tests here:
16+
// https://github.com/vitest-dev/vitest/blob/main/test/core/test/mock-internals.test.ts#L27
17+
//
18+
// - so this looks like a reasonable approach
719
export async function dynamicImport(path: string) {
820
return import(path)
921
}

.github/actions/find/src/findForUrl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ export async function findForUrl(
3535
rawFindings = await new AxeBuilder({page}).analyze()
3636
}
3737

38-
// - this condition is not required, but makes it easier to make assertions
39-
// in unit tests on whether 'loadPlugins' was called or not
38+
// - this if condition is not required, but makes it easier to make assertions
39+
// in unit tests on whether 'loadPlugins' was called or not (it does have the added
40+
// benefit of completely skipping plugin loading if we just want axe - so thats
41+
// a minor performance boost)
4042
// - alternatively, we can wrap the 'plugin.default(...)' call in another function
4143
// and make assertions on whether that function was called or not
4244
// - the other option is to wrap each plugin in a class instance

0 commit comments

Comments
 (0)