Skip to content

Commit

Permalink
test: mock context
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Dec 9, 2023
1 parent d42b905 commit a1d99cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .nycrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": 95,
"branches": 94,
"lines": 99,
"functions": 99,
"statements": 99
Expand Down
5 changes: 2 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,8 @@ module.exports = {
isRuleTesterConstruction(declarator.init) &&
declarator.id.type === 'Identifier'
) {
(sourceCode.getDeclaredVariables || context.getDeclaredVariables)(
declarator
).forEach((variable) => {
const vars = sourceCode.getDeclaredVariables ? sourceCode.getDeclaredVariables(declarator) : context.getDeclaredVariables;

Check failure on line 471 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Replace `·?·sourceCode.getDeclaredVariables(declarator)` with `⏎··············?·sourceCode.getDeclaredVariables(declarator)⏎·············`

Check failure on line 471 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Replace `·?·sourceCode.getDeclaredVariables(declarator)` with `⏎··············?·sourceCode.getDeclaredVariables(declarator)⏎·············`
vars.forEach((variable) => {
variable.references
.filter((ref) => ref.isRead())
.forEach((ref) => variableIdentifiers.add(ref.identifier));
Expand Down
24 changes: 21 additions & 3 deletions tests/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,14 @@ describe('utils', () => {
sourceType: 'script',
nodejsScope: true,
});
const context = {
sourceCode: {
getDeclaredVariables:
scopeManager.getDeclaredVariables.bind(scopeManager),
},
}; // mock object
assert.deepEqual(
utils.getTestInfo(scopeManager, ast),
utils.getTestInfo(context, ast),
[],
'Expected no tests to be found'
);
Expand Down Expand Up @@ -827,7 +833,13 @@ describe('utils', () => {
sourceType: 'script',
nodejsScope: true,
});
const testInfo = utils.getTestInfo(scopeManager, ast);
const context = {
sourceCode: {
getDeclaredVariables:
scopeManager.getDeclaredVariables.bind(scopeManager),
},
}; // mock object
const testInfo = utils.getTestInfo(context, ast);

assert.strictEqual(
testInfo.length,
Expand Down Expand Up @@ -1021,7 +1033,13 @@ describe('utils', () => {
sourceType: 'script',
nodejsScope: true,
});
const testInfo = utils.getTestInfo(scopeManager, ast);
const context = {
sourceCode: {
getDeclaredVariables:
scopeManager.getDeclaredVariables.bind(scopeManager),
},
}; // mock object
const testInfo = utils.getTestInfo(context, ast);

assert.strictEqual(
testInfo.length,
Expand Down

0 comments on commit a1d99cc

Please sign in to comment.