Skip to content

refactor: Add a few lint rules to test files in /spec #9815

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

Merged
merged 1 commit into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions spec/Adapters/Auth/gcenter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ describe('GameCenterAuth Adapter', function () {
const gcProd4 = fs.readFileSync(path.resolve(__dirname, '../../support/cert/gc-prod-4.cer'));
const digicertPem = fs.readFileSync(path.resolve(__dirname, '../../support/cert/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem')).toString();

mockFetch([
{
url: 'https://static.gc.apple.com/public-key/gc-prod-4.cer',
method: 'GET',
response: {
ok: true,
headers: new Map(),
arrayBuffer: () => Promise.resolve(
gcProd4.buffer.slice(gcProd4.byteOffset, gcProd4.byteOffset + gcProd4.length)
),
mockFetch([
{
url: 'https://static.gc.apple.com/public-key/gc-prod-4.cer',
method: 'GET',
response: {
ok: true,
headers: new Map(),
arrayBuffer: () => Promise.resolve(
gcProd4.buffer.slice(gcProd4.byteOffset, gcProd4.byteOffset + gcProd4.length)
),
},
},
},
{
url: 'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem',
method: 'GET',
response: {
ok: true,
headers: new Map([['content-type', 'application/x-pem-file'], ['content-length', digicertPem.length.toString()]]),
text: () => Promise.resolve(digicertPem),
},
}
]);
{
url: 'https://cacerts.digicert.com/DigiCertTrustedG4CodeSigningRSA4096SHA3842021CA1.crt.pem',
method: 'GET',
response: {
ok: true,
headers: new Map([['content-type', 'application/x-pem-file'], ['content-length', digicertPem.length.toString()]]),
text: () => Promise.resolve(digicertPem),
},
}
]);
});

describe('Test config failing due to missing params or wrong types', function () {
Expand Down
8 changes: 4 additions & 4 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3502,9 +3502,9 @@ describe('afterLogin hook', () => {
'X-Parse-REST-API-Key': 'rest',
'X-Parse-Cloud-Context': '{"a":"a"}',
},
body: JSON.stringify({_context: { hello: 'world' }}),
body: JSON.stringify({ _context: { hello: 'world' } }),
});

Comment on lines 3503 to +3507
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Avoid double-encoding the request body

lib/request already JSON-serialises plain objects that are passed via the body field (see other tests in this file).
Passing a pre-stringified payload here will therefore lead to a double JSON encoding on the wire:

{"body":"{\"_context\":{\"hello\":\"world\"}}"}

which breaks the server-side deserialisation and defeats the purpose of the test.

-      body: JSON.stringify({ _context: { hello: 'world' } }),
+      body: { _context: { hello: 'world' } },

Run the test suite after applying the patch – this part currently fails if the server expects a structured JSON object.


I’ll verify how lib/request handles the body field and check other tests in spec/CloudCode.spec.js for examples of plain-object bodies.

#!/bin/bash
set -e

echo "1) Sample 'body:' usages in spec/CloudCode.spec.js:"
rg -n "body:" spec/CloudCode.spec.js | head -n 20 || true

echo
echo "2) Locating lib/request implementation:"
REQUEST_FILE=$(fd -t f --hidden --glob "request.js" lib || echo "")
if [[ -z "$REQUEST_FILE" ]]; then
  echo "lib/request.js not found under lib/, searching entire repo..."
  REQUEST_FILE=$(fd -t f --hidden --glob "request.js" .)
fi
echo "Found: $REQUEST_FILE"

echo
echo "3) Inspecting lib/request.js for JSON serialization logic:"
sed -n '1,200p' "$REQUEST_FILE"

I’ll verify the body handling in lib/request and how other tests use plain-object bodies:

#!/usr/bin/env bash
set -e

# 1) Locate the request implementation
REQUEST_FILE=$(fd -t f --glob "request.js" lib | head -n1)
if [[ -z "$REQUEST_FILE" ]]; then
  REQUEST_FILE=$(fd -t f --glob "request.js" . | head -n1)
fi
echo "Using: $REQUEST_FILE"

# 2) Show the top of lib/request.js to find body serialization logic
echo "----- lib/request.js (first 200 lines) -----"
sed -n '1,200p' "$REQUEST_FILE"

# 3) Look for JSON.stringify usage in lib/request.js
echo
echo "----- JSON.stringify calls in lib/request.js -----"
rg -n "JSON.stringify" "$REQUEST_FILE" || echo "No JSON.stringify found"

# 4) See how other tests pass `body` in CloudCode.spec.js
echo
echo "----- Examples of body: in spec/CloudCode.spec.js -----"
rg -n "body:" spec/CloudCode.spec.js | head -n20 || true

Avoid double-encoding the request body

lib/request already JSON-serializes plain objects passed via the body field. Wrapping the payload in JSON.stringify here causes a double-encoding on the wire and breaks server-side deserialization.

Locations to update:

  • spec/CloudCode.spec.js around line 3503

Required change:

-      body: JSON.stringify({ _context: { hello: 'world' } }),
+      body: { _context: { hello: 'world' } },

Run the test suite after applying this patch to confirm the fix.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'X-Parse-Cloud-Context': '{"a":"a"}',
},
body: JSON.stringify({_context: { hello: 'world' }}),
body: JSON.stringify({ _context: { hello: 'world' } }),
});
'X-Parse-Cloud-Context': '{"a":"a"}',
},
body: { _context: { hello: 'world' } },
});
🤖 Prompt for AI Agents
In spec/CloudCode.spec.js around lines 3503 to 3507, the request body is being
double-encoded by calling JSON.stringify on an object that lib/request already
serializes. Remove the JSON.stringify call and pass the plain object directly to
the body field to avoid double-encoding and ensure proper server-side
deserialization.

});

it('should have access to context when saving a new object', async () => {
Expand Down Expand Up @@ -3929,7 +3929,7 @@ describe('saveFile hooks', () => {
});
});

describe('Parse.File hooks', () => {
describe('Parse.File hooks', () => {
it('find hooks should run', async () => {
const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
await file.save({ useMasterKey: true });
Expand Down Expand Up @@ -4047,7 +4047,7 @@ describe('Parse.File hooks', () => {
});
expect(response.headers['content-disposition']).toBe(`attachment;filename=${file._name}`);
});
});
});

describe('Cloud Config hooks', () => {
function testConfig() {
Expand Down
8 changes: 3 additions & 5 deletions spec/EmailVerificationToken.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ describe('Email Verification Token Expiration:', () => {

it_id('b6c87f35-d887-477d-bc86-a9217a424f53')(it)('setting the email on the user should set a new email verification token and new expiration date for the token when expire email verify token flag is set', async () => {
const user = new Parse.User();
let userBeforeEmailReset;

let sendEmailOptions;
const sendPromise = resolvingPromise();
Expand Down Expand Up @@ -680,7 +679,7 @@ describe('Email Verification Token Expiration:', () => {
return results[0];
});
expect(typeof userFromDb).toBe('object');
userBeforeEmailReset = userFromDb;
const userBeforeEmailReset = userFromDb;

// trigger another token generation by setting the email
user.set('email', '[email protected]');
Expand Down Expand Up @@ -713,7 +712,6 @@ describe('Email Verification Token Expiration:', () => {
const user = new Parse.User();
let sendEmailOptions;
let sendVerificationEmailCallCount = 0;
let userBeforeRequest;
const promise1 = resolvingPromise();
const promise2 = resolvingPromise();
const emailAdapter = {
Expand Down Expand Up @@ -748,7 +746,7 @@ describe('Email Verification Token Expiration:', () => {
return results[0];
});
// store this user before we make our email request
userBeforeRequest = newUser;
const userBeforeRequest = newUser;

expect(sendVerificationEmailCallCount).toBe(1);

Expand Down Expand Up @@ -1011,7 +1009,7 @@ describe('Email Verification Token Expiration:', () => {
})
.then(fail)
.catch(response => response);

expect(response.status).toBe(400);
expect(sendVerificationEmailCallCount).toBe(0);
expect(sendEmailOptions).not.toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ describe('ParseGraphQLServer', () => {
}

beforeEach(async () => {
await createGQLFromParseServer(parseServer);
await createGQLFromParseServer(parseServer);

const subscriptionClient = new SubscriptionClient(
'ws://localhost:13377/subscriptions',
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ describe('ParseLiveQuery', function () {
await sleep(100);
expect(server.liveQueryServer.server.address()).toBeNull();
expect(server.liveQueryServer.subscriber.isOpen).toBeFalse();

liveQueryConnectionCount = await getConnectionsCount(server.liveQueryServer.server);
expect(liveQueryConnectionCount).toBe(0);
});
Expand Down
22 changes: 11 additions & 11 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5312,7 +5312,7 @@ describe('Parse.Query testing', () => {
const child = new Parse.Object('Child');
child.set('key', 'value');
await child.save();

const parent = new Parse.Object('Parent');
parent.set('some', {
nested: {
Expand All @@ -5322,19 +5322,19 @@ describe('Parse.Query testing', () => {
},
});
await parent.save();

const query1 = await new Parse.Query('Parent')
.equalTo('some.nested.key.child', child)
.find();

expect(query1.length).toEqual(1);
});

it('queries nested key using containedIn', async () => {
const child = new Parse.Object('Child');
child.set('key', 'value');
await child.save();

const parent = new Parse.Object('Parent');
parent.set('some', {
nested: {
Expand All @@ -5344,19 +5344,19 @@ describe('Parse.Query testing', () => {
},
});
await parent.save();

const query1 = await new Parse.Query('Parent')
.containedIn('some.nested.key.child', [child])
.find();

expect(query1.length).toEqual(1);
});

it('queries nested key using matchesQuery', async () => {
const child = new Parse.Object('Child');
child.set('key', 'value');
await child.save();

const parent = new Parse.Object('Parent');
parent.set('some', {
nested: {
Expand All @@ -5366,11 +5366,11 @@ describe('Parse.Query testing', () => {
},
});
await parent.save();

const query1 = await new Parse.Query('Parent')
.matchesQuery('some.nested.key.child', new Parse.Query('Child').equalTo('key', 'value'))
.find();

expect(query1.length).toEqual(1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/Utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Utils', () => {
]
for (const value of values) {
expect(Utils.encodeForUrl(value.input)).toBe(value.output);
}
}
});
});

Expand Down
18 changes: 14 additions & 4 deletions spec/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ module.exports = [
},
},
rules: {
"no-console": "off",
"no-var": "error",
"no-unused-vars": "off",
indent: ["error", 2, { SwitchCase: 1 }],
"linebreak-style": ["error", "unix"],
"no-trailing-spaces": "error",
"eol-last": "error",
"space-in-parens": ["error", "never"],
"no-multiple-empty-lines": "warn",
"prefer-const": "error",
"space-infix-ops": "error",
"no-useless-escape": "off",
}
"require-atomic-updates": "off",
"object-curly-spacing": ["error", "always"],
curly: ["error", "all"],
"block-spacing": ["error", "always"],
"no-unused-vars": "off",
},
},
];
2 changes: 1 addition & 1 deletion spec/support/CurrentSpecReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ global.retryFlakyTests = function() {
};
}

module.exports = CurrentSpecReporter;
module.exports = CurrentSpecReporter;