Key changes: - Run URL checks more frequently on every change. - Introduce environment variable to randomly select and limit URLs tested, this way the tests will provide quicker feedback on code changes. Other supporting changes: - Log more information about test before running the test to enable easier troubleshooting. - Move shuffle function for arrays for reusability and missing tests.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { shuffle } from '@/application/Common/Shuffle';
|
|
|
|
describe('Shuffle', () => {
|
|
describe('shuffle', () => {
|
|
it('returns a new array', () => {
|
|
// arrange
|
|
const inputArray = ['a', 'b', 'c', 'd'];
|
|
// act
|
|
const result = shuffle(inputArray);
|
|
// assert
|
|
expect(result).not.to.equal(inputArray);
|
|
});
|
|
|
|
it('returns an array of the same length', () => {
|
|
// arrange
|
|
const inputArray = ['a', 'b', 'c', 'd'];
|
|
// act
|
|
const result = shuffle(inputArray);
|
|
// assert
|
|
expect(result.length).toBe(inputArray.length);
|
|
});
|
|
|
|
it('contains the same elements', () => {
|
|
// arrange
|
|
const inputArray = ['a', 'b', 'c', 'd'];
|
|
// act
|
|
const result = shuffle(inputArray);
|
|
// assert
|
|
expect(result).to.have.members(inputArray);
|
|
});
|
|
|
|
it('does not modify the input array', () => {
|
|
// arrange
|
|
const inputArray = ['a', 'b', 'c', 'd'];
|
|
const inputArrayCopy = [...inputArray];
|
|
// act
|
|
shuffle(inputArray);
|
|
// assert
|
|
expect(inputArray).to.deep.equal(inputArrayCopy);
|
|
});
|
|
|
|
it('handles an empty array correctly', () => {
|
|
// arrange
|
|
const inputArray: string[] = [];
|
|
// act
|
|
const result = shuffle(inputArray);
|
|
// assert
|
|
expect(result).have.lengthOf(0);
|
|
});
|
|
});
|
|
});
|