Skip to content

test: add deepStrictEqual tests for better accuracy #115

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lumirlumir
Copy link
Member

@lumirlumir lumirlumir commented Jun 20, 2025

Prerequisites checklist

What is the purpose of this pull request?

Hello,

In this PR, I've added several test assertions in tests/languages/json-source-code.test.js to use assert.deepStrictEqual.

This change ensures that complex objects are compared by their deep structure rather than just by reference, improving the reliability of the tests.

These test cases help prevent unintended changes to deeply nested properties.

What changes did you make? (Give an overview)

Related Issues

Is there anything you'd like reviewers to focus on?

@lumirlumir lumirlumir changed the title test: replace strictEqual with deepStrictEqual for better assertion accuracy test: replace strictEqual with deepStrictEqual for better accuracy Jun 20, 2025
@eslint eslint deleted a comment from eslint-github-bot bot Jun 20, 2025
@lumirlumir lumirlumir changed the title test: replace strictEqual with deepStrictEqual for better accuracy test: add deepStrictEqual test for better accuracy Jun 20, 2025
@lumirlumir lumirlumir marked this pull request as draft June 20, 2025 10:50
@lumirlumir lumirlumir force-pushed the test-replace-strictequal-with-deepstrictequal-for-better-assertion-accuracy branch from aef67d1 to a84120c Compare June 20, 2025 10:58
@lumirlumir lumirlumir changed the title test: add deepStrictEqual test for better accuracy test: add deepStrictEqual to test for better accuracy Jun 20, 2025
@lumirlumir
Copy link
Member Author

@mdjermanovic Thanks for your guidance — it gave me a good opportunity to think more carefully about deep vs. shallow equality.

I've added a commit that addresses your comment, and this change doesn't affect the existing behavior.

@lumirlumir lumirlumir marked this pull request as ready for review June 20, 2025 11:09
@lumirlumir lumirlumir requested a review from mdjermanovic June 20, 2025 11:09
@lumirlumir lumirlumir changed the title test: add deepStrictEqual to test for better accuracy test: add deepStrictEqual test for better accuracy Jun 20, 2025
@mdjermanovic mdjermanovic changed the title test: add deepStrictEqual test for better accuracy test: add deepStrictEqual tests for better accuracy Jun 20, 2025
@lumirlumir
Copy link
Member Author

lumirlumir commented Jun 20, 2025

For more context on this change:

Without the deepStrictEqual test, we can't verify whether the ast has changed due to unintended side effects.

For example, the previous test case "should create a JSONSourceCode instance" wouldn’t catch the issue shown below because they don't inspect nested properties. (This is a simplified example to illustrate the point — real-world cases might differ slightly.)

	/**
	 * Creates a new instance.
	 * @param {Object} options The options for the instance.
	 * @param {string} options.text The source code text.
	 * @param {DocumentNode} options.ast The root AST node.
	 */
	constructor({ text, ast }) {
		super({ text, ast });
		this.ast = ast;
+		this.ast.loc = {start: {line: 1, column: 1, offset: 0}, end: {line: 1, column: 2, offset: 1}};
		this.comments = ast.tokens
			? ast.tokens.filter(token => token.type.endsWith("Comment"))
			: [];
	}

@nzakas nzakas added this to Triage Jun 20, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 20, 2025
@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jun 20, 2025
@nzakas
Copy link
Member

nzakas commented Jun 20, 2025

I'm not sure I see the value in these changes. Fundamentally, these tests are not interested in whether or not the data structure has changed, they only care that an expected value is returned and that the value is === to the stored value. It seems beyond the scope of the tests to care whether the object has been mutated in some way. I'm not sure that's a guarantee we need (or want) to make.

The example given (mutating the AST inside the JSONSourceCode constructor) isn't a situation we're concerned with because we are in 100% control of it. If we need to mutate the AST in some way, that's okay, because rules don't receive the AST until after JSONSourceCode is instantiated.

@lumirlumir lumirlumir marked this pull request as draft June 21, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

3 participants