Skip to content

Commit 0faa4e6

Browse files
committed
test: mock context
1 parent d485783 commit 0faa4e6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.nycrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"branches": 95,
2+
"branches": 94,
33
"lines": 99,
44
"functions": 99,
55
"statements": 99

lib/utils.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,10 @@ module.exports = {
468468
isRuleTesterConstruction(declarator.init) &&
469469
declarator.id.type === 'Identifier'
470470
) {
471-
(sourceCode.getDeclaredVariables || context.getDeclaredVariables)(
472-
declarator
473-
).forEach((variable) => {
471+
const vars = sourceCode.getDeclaredVariables
472+
? sourceCode.getDeclaredVariables(declarator)
473+
: context.getDeclaredVariables(declarator);
474+
vars.forEach((variable) => {
474475
variable.references
475476
.filter((ref) => ref.isRead())
476477
.forEach((ref) => variableIdentifiers.add(ref.identifier));

tests/lib/utils.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,14 @@ describe('utils', () => {
761761
sourceType: 'script',
762762
nodejsScope: true,
763763
});
764+
const context = {
765+
sourceCode: {
766+
getDeclaredVariables:
767+
scopeManager.getDeclaredVariables.bind(scopeManager),
768+
},
769+
}; // mock object
764770
assert.deepEqual(
765-
utils.getTestInfo(scopeManager, ast),
771+
utils.getTestInfo(context, ast),
766772
[],
767773
'Expected no tests to be found'
768774
);
@@ -827,7 +833,13 @@ describe('utils', () => {
827833
sourceType: 'script',
828834
nodejsScope: true,
829835
});
830-
const testInfo = utils.getTestInfo(scopeManager, ast);
836+
const context = {
837+
sourceCode: {
838+
getDeclaredVariables:
839+
scopeManager.getDeclaredVariables.bind(scopeManager),
840+
},
841+
}; // mock object
842+
const testInfo = utils.getTestInfo(context, ast);
831843

832844
assert.strictEqual(
833845
testInfo.length,
@@ -1021,7 +1033,13 @@ describe('utils', () => {
10211033
sourceType: 'script',
10221034
nodejsScope: true,
10231035
});
1024-
const testInfo = utils.getTestInfo(scopeManager, ast);
1036+
const context = {
1037+
sourceCode: {
1038+
getDeclaredVariables:
1039+
scopeManager.getDeclaredVariables.bind(scopeManager),
1040+
},
1041+
}; // mock object
1042+
const testInfo = utils.getTestInfo(context, ast);
10251043

10261044
assert.strictEqual(
10271045
testInfo.length,

0 commit comments

Comments
 (0)