-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Jest; DoctrineArray tests * Run tests in CI
- Loading branch information
1 parent
68bdf4c
commit 3aab805
Showing
8 changed files
with
2,203 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DoctrineArray } from './DoctrineArray'; | ||
|
||
test('DoctrineArray can serialize an empty array', () => { | ||
const doctrine = new DoctrineArray(); | ||
const serialized = doctrine.serialize(); | ||
expect(serialized).toEqual('a:0:{}'); | ||
}); | ||
|
||
test('DoctrineArray can serialize an array with one number', () => { | ||
const doctrine = new DoctrineArray(); | ||
doctrine.push(33027); | ||
const serialized = doctrine.serialize(); | ||
expect(serialized).toEqual('a:1:{i:0;i:33027;}'); | ||
}); | ||
|
||
test('DoctrineArray can serialize an array with two numbers', () => { | ||
const doctrine = new DoctrineArray(); | ||
doctrine.push(...[33027, 5333]); | ||
const serialized = doctrine.serialize(); | ||
expect(serialized).toEqual('a:2:{i:0;i:33027;i:1;i:5333;}'); | ||
}); | ||
|
||
test('DoctrineArray can deserialize an empty array', () => { | ||
const doctrine = DoctrineArray.deserialize('a:0:{}'); | ||
expect(doctrine).toHaveLength(0); | ||
}); | ||
|
||
test('DoctrineArray can deserialize an array with one number', () => { | ||
const doctrine = DoctrineArray.deserialize('a:1:{i:0;i:33027;}'); | ||
expect(doctrine).toHaveLength(1); | ||
expect(doctrine[0]).toStrictEqual(33027); | ||
}); | ||
|
||
test('DoctrineArray can deserialize an array with two numbers', () => { | ||
const doctrine = DoctrineArray.deserialize('a:2:{i:0;i:33027;i:1;i:5333;}'); | ||
expect(doctrine).toHaveLength(2); | ||
expect(doctrine[0]).toStrictEqual(33027); | ||
expect(doctrine[1]).toStrictEqual(5333); | ||
}); | ||
|
||
test('DoctrineArray can serialize and deserialize an array with many numbers', () => { | ||
const data = new Array(1000).fill(0).map(() => Math.floor(Math.random() * 1000)); | ||
const doctrine = new DoctrineArray(); | ||
doctrine.push(...data); | ||
const serialized = doctrine.serialize(); | ||
const result = DoctrineArray.deserialize(serialized); | ||
|
||
expect(result).toHaveLength(data.length); | ||
for (let i = 0; i < data.length; i++) { | ||
expect(result[i]).toStrictEqual(data[i]); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = { | ||
collectCoverage: true, | ||
// on node 14.x coverage provider v8 offers good speed and more or less good report | ||
coverageProvider: 'v8', | ||
collectCoverageFrom: [ | ||
'**/*.{js,jsx,ts,tsx}', | ||
'!**/*.d.ts', | ||
'!**/node_modules/**', | ||
'!<rootDir>/out/**', | ||
'!<rootDir>/.next/**', | ||
'!<rootDir>/*.config.js', | ||
'!<rootDir>/coverage/**', | ||
], | ||
moduleNameMapper: { | ||
// Handle CSS imports (with CSS modules) | ||
// https://jestjs.io/docs/webpack#mocking-css-modules | ||
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', | ||
|
||
// Handle CSS imports (without CSS modules) | ||
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js', | ||
|
||
// Handle image imports | ||
// https://jestjs.io/docs/webpack#handling-static-assets | ||
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i': `<rootDir>/__mocks__/fileMock.js`, | ||
|
||
// Handle module aliases | ||
'^@/components/(.*)$': '<rootDir>/components/$1', | ||
}, | ||
// Add more setup options before each test is run | ||
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'], | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
// Use babel-jest to transpile tests with the next/babel preset | ||
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object | ||
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], | ||
}, | ||
transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss)$'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.