Skip to content

test: Refactor tests to bump jest and jsdom to 29.4.1 #1733

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 2 commits into from
Feb 6, 2023
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
9,813 changes: 4,709 additions & 5,104 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@semantic-release/npm": "9.0.2",
"@semantic-release/release-notes-generator": "10.0.3",
"babel-eslint": "10.1.0",
"babel-jest": "24.9.0",
"babel-jest": "29.4.1",
"babel-plugin-inline-package-json": "2.0.0",
"babel-plugin-minify-dead-code-elimination": "0.5.2",
"babel-plugin-transform-inline-environment-variables": "0.4.3",
Expand All @@ -77,7 +77,8 @@
"jasmine": "3.5.0",
"jasmine-reporters": "2.5.2",
"jasmine-spec-reporter": "7.0.0",
"jest": "24.9.0",
"jest": "29.4.1",
"jest-environment-jsdom": "29.4.1",
"jsdoc": "3.6.3",
"jsdoc-babel": "0.5.0",
"lint-staged": "10.5.3",
Expand Down Expand Up @@ -150,8 +151,6 @@
"/node_modules/",
"package.json"
],
"setupFilesAfterEnv": [
"./setup-jest.js"
]
"testEnvironment": "jsdom"
}
}
3 changes: 0 additions & 3 deletions setup-jest.js

This file was deleted.

5 changes: 1 addition & 4 deletions src/__tests__/EventuallyQueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ const ParseObject = require('../ParseObject');
const RESTController = require('../RESTController');
const Storage = require('../Storage');
const mockXHR = require('./test_helpers/mockXHR');
const flushPromises = require('./test_helpers/flushPromises');

CoreManager.setInstallationController({
currentInstallationId() {
return Promise.resolve('iid');
},
});

function flushPromises() {
return new Promise(resolve => setImmediate(resolve));
}

describe('EventuallyQueue', () => {
beforeEach(async () => {
jest.clearAllMocks();
Expand Down
45 changes: 6 additions & 39 deletions src/__tests__/Hooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,117 +129,84 @@ describe('Hooks', () => {
]);
});

it('shoud throw invalid create', async done => {
it('shoud throw invalid create', async () => {
expect.assertions(10);
const p1 = Hooks.create({ functionName: 'myFunction' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p2 = Hooks.create({ url: 'http://dummy.com' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p3 = Hooks.create({ className: 'MyClass' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p4 = Hooks.create({ className: 'MyClass', url: 'http://dummy.com' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p5 = Hooks.create({ className: 'MyClass', triggerName: 'beforeSave' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

await Promise.all([p1, p2, p3, p4, p5]);
done();
});

it('shoud throw invalid update', async done => {
it('shoud throw invalid update', async () => {
expect.assertions(6);
const p1 = Hooks.update({ functionssName: 'myFunction' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p2 = Hooks.update({ className: 'MyClass' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p3 = Hooks.update({ className: 'MyClass', url: 'http://dummy.com' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});
await Promise.all([p1, p2, p3]);
done();
});

it('shoud throw invalid remove', async done => {
it('shoud throw invalid remove', async () => {
expect.assertions(6);
const p1 = Hooks.remove({ functionssName: 'myFunction' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p2 = Hooks.remove({ className: 'MyClass' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

const p3 = Hooks.remove({ className: 'MyClass', url: 'http://dummy.com' })
.then(() => {
done.fail('should not succeed');
})
.catch(err => {
expect(err.code).toBe(143);
expect(err.error).toBe('invalid hook declaration');
});

await Promise.all([p1, p2, p3]);
done();
});

it('should sendRequest', async () => {
Expand Down
26 changes: 11 additions & 15 deletions src/__tests__/Parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ jest.setMock('../EventuallyQueue', { poll: jest.fn() });
global.indexedDB = require('./test_helpers/mockIndexedDB');
const CoreManager = require('../CoreManager');
const EventuallyQueue = require('../EventuallyQueue');
const Parse = require('../Parse');

describe('Parse module', () => {
let Parse;
beforeEach(() => {
jest.isolateModules(() => {
Parse = require('../Parse');
});
});

it('can be initialized with keys', () => {
Parse.initialize('A', 'B');
expect(CoreManager.get('APPLICATION_ID')).toBe('A');
Expand Down Expand Up @@ -239,13 +233,15 @@ describe('Parse module', () => {
});

it('can get IndexedDB storage', () => {
expect(Parse.IndexedDB).toBeUndefined();
process.env.PARSE_BUILD = 'browser';
const ParseInstance = require('../Parse');
expect(ParseInstance.IndexedDB).toBeDefined();
CoreManager.setStorageController(ParseInstance.IndexedDB);
const currentStorage = CoreManager.getStorageController();
expect(currentStorage).toEqual(ParseInstance.IndexedDB);
process.env.PARSE_BUILD = 'node';
jest.isolateModules(() => {
expect(Parse.IndexedDB).toBeUndefined();
process.env.PARSE_BUILD = 'browser';
const ParseInstance = require('../Parse');
expect(ParseInstance.IndexedDB).toBeDefined();
CoreManager.setStorageController(ParseInstance.IndexedDB);
const currentStorage = CoreManager.getStorageController();
expect(currentStorage).toEqual(ParseInstance.IndexedDB);
process.env.PARSE_BUILD = 'node';
});
});
});
4 changes: 2 additions & 2 deletions src/__tests__/ParseFile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,13 @@ describe('FileController', () => {
expect(request).toHaveBeenCalled();
});

it('should throw error if file deleted without name', async done => {
it('should throw error if file deleted without name', async () => {
expect.assertions(1);
const file = new ParseFile('', [1, 2, 3]);
try {
await file.destroy();
} catch (e) {
expect(e.code).toBe(ParseError.FILE_DELETE_UNNAMED_ERROR);
done();
}
});

Expand Down
Loading