Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate affected tests to esm (#4158)
* chore: migrate affected tests to esm * chore: fix prettier
- Loading branch information
1 parent
3dd9f74
commit 0577c15
Showing
14 changed files
with
143 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { DependencyGraph } from './dependency-graph.mjs' | ||
export { fileVisitor } from './file-visitor.mjs' | ||
export * from './visitor-plugins.mjs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
tools/project-graph/visitor-plugins.js → tools/project-graph/visitor-plugins.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { join } from 'path' | ||
|
||
import test from 'ava' | ||
import glob from 'fast-glob' | ||
import mock from 'mock-fs' | ||
import { stub, createSandbox } from 'sinon' | ||
|
||
import { simpleMockedFileSystem } from './utils/file-systems.mjs' | ||
|
||
/** | ||
* Get a list of affected files for a mocked file system | ||
* @param {string[]} changedFiles The list of changed files | ||
* @param {Record<string, string>} fileSystem The mocked file system | ||
* @returns Returns a list of affected files | ||
*/ | ||
const getAffectedFilesFromMock = async (changedFiles, fileSystem = simpleMockedFileSystem) => { | ||
const mockedTestFiles = Object.keys(fileSystem).filter((file) => file.match(/\.test\.m?js$/gm)) | ||
const globStub = stub(glob, 'sync').returns(mockedTestFiles) | ||
|
||
const { getAffectedFiles } = await import('../affected-test.mjs') | ||
mock(fileSystem) | ||
|
||
const affectedFiles = getAffectedFiles(changedFiles) | ||
|
||
mock.restore() | ||
globStub.restore() | ||
|
||
return { affectedFiles, mockedTestFiles } | ||
} | ||
|
||
test.beforeEach((t) => { | ||
t.context.sandbox = createSandbox() | ||
}) | ||
|
||
test.afterEach((t) => { | ||
t.context.sandbox.restore() | ||
}) | ||
|
||
test.only('should get all files marked as affected when the package.json is touched', async (t) => { | ||
const consoleStub = t.context.sandbox.stub(console, 'log').callsFake(() => {}) | ||
const { affectedFiles, mockedTestFiles } = await getAffectedFilesFromMock(['package.json']) | ||
|
||
t.truthy(consoleStub.firstCall.calledWith('All files are affected based on the changeset')) | ||
t.deepEqual(affectedFiles, mockedTestFiles) | ||
}) | ||
|
||
test.serial('should get all files marked as affected when the npm-shrinkwrap.json is touched', async (t) => { | ||
const consoleStub = t.context.sandbox.stub(console, 'log').callsFake(() => {}) | ||
const { affectedFiles, mockedTestFiles } = await getAffectedFilesFromMock(['npm-shrinkwrap.json']) | ||
|
||
t.truthy(consoleStub.firstCall.calledWith('All files are affected based on the changeset')) | ||
t.deepEqual(affectedFiles, mockedTestFiles) | ||
}) | ||
|
||
test.serial('should get all files marked as affected when a leaf is touched that both tests depend on', async (t) => { | ||
const consoleStub = stub(console, 'log').callsFake(() => {}) | ||
const { affectedFiles, mockedTestFiles } = await getAffectedFilesFromMock([join('src/d.js')]) | ||
|
||
t.truthy(consoleStub.notCalled) | ||
t.deepEqual(affectedFiles, mockedTestFiles) | ||
consoleStub.restore() | ||
}) | ||
|
||
test.serial('should only one test affected if a file for it was called', async (t) => { | ||
const { affectedFiles } = await getAffectedFilesFromMock([join('src/nested/b.js')]) | ||
|
||
t.deepEqual(affectedFiles, [join('tests/a.test.js')]) | ||
}) | ||
|
||
test.serial('should not have any file affected if a different file like a readme was affected', async (t) => { | ||
const { affectedFiles } = await getAffectedFilesFromMock(['README.md']) | ||
|
||
t.is(affectedFiles.length, 0) | ||
}) |
4 changes: 2 additions & 2 deletions
4
tools/tests/dependency-graph.test.js → tools/tests/dependency-graph.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
0577c15
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.
📊 Benchmark results
Package size: 363 MB