Client - move unit tests to Vitest

This commit is contained in:
Sam 2023-11-11 17:12:20 +01:00
parent 1befae927d
commit e9c482c585
18 changed files with 838 additions and 300 deletions

View File

@ -6,6 +6,7 @@
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"test:unit": "vitest",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
@ -44,22 +45,23 @@
"@intlify/vue-i18n-loader": "^4.2.0",
"@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2",
"@types/chai": "^4.3.10",
"@types/mocha": "^10.0.4",
"@types/jsdom": "^21.1.3",
"@types/node": "^20.9.0",
"@types/sanitize-html": "^2.9.4",
"@vitejs/plugin-vue": "^4.4.0",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^12.0.0",
"@vue/test-utils": "^2.4.1",
"@vue/tsconfig": "^0.4.0",
"chai": "^4.3.10",
"eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0",
"jsdom": "^22.1.0",
"npm-run-all2": "^6.1.1",
"prettier": "^3.0.3",
"sass": "^1.69.5",
"typescript": "~5.2.0",
"vite": "^4.4.11",
"vitest": "^0.34.6",
"vue-tsc": "^1.8.19"
}
}

View File

@ -1,13 +0,0 @@
// import { expect } from 'chai'
// import { shallowMount } from '@vue/test-utils'
// import NavBar from '@/components/NavBar.vue'
//
// describe('NavBar.vue', () => {
// it('renders props.msg when passed', () => {
// const msg = 'new message'
// const wrapper = shallowMount(NavBar, {
// props: { msg },
// })
// expect(wrapper.text()).to.include(msg)
// })
// })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import {
defaultPerPage,
@ -50,13 +50,9 @@ describe('getNumberQueryValue', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
getNumberQueryValue(
testParams.inputValue,
testParams.inputDefaultValue
),
testParams.expectedValue
)
expect(
getNumberQueryValue(testParams.inputValue, testParams.inputDefaultValue)
).toBe(testParams.expectedValue)
})
})
})
@ -85,14 +81,13 @@ describe('getStringQueryValue', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
expect(
getStringQueryValue(
testParams.inputValue,
sortList,
testParams.inputDefaultValue
),
testParams.expectedValue
)
)
).toBe(testParams.expectedValue)
})
})
})
@ -169,19 +164,18 @@ describe('getQuery', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
getQuery(testParams.inputLocationQuery, orderByList, defaultOrderBy, {
defaultSort,
}),
testParams.expectedQuery
)
})
).toStrictEqual(testParams.expectedQuery)
})
})
})
describe('getQuery w/ default values', () => {
it('returns default query if location query is an empty object', () => {
assert.deepEqual(getQuery({}, orderByList, defaultOrderBy), {
expect(getQuery({}, orderByList, defaultOrderBy)).toStrictEqual({
page: 1,
per_page: 10,
order: 'asc',
@ -199,46 +193,48 @@ describe('getQuery w/ default values and input pagination payload', () => {
}
it('returns query updated with default values', () => {
assert.deepEqual(
getQuery({}, orderByList, defaultOrderBy, { query: inputQuery }),
{
page: 1,
per_page: 10,
order: 'asc',
order_by: defaultOrderBy,
}
)
expect(
getQuery({}, orderByList, defaultOrderBy, { query: inputQuery })
).toStrictEqual({
page: 1,
per_page: 10,
order: 'asc',
order_by: defaultOrderBy,
})
})
it('returns query updated with input values', () => {
assert.deepEqual(
expect(
getQuery({}, orderByList, defaultOrderBy, {
defaultSort: 'desc',
query: inputQuery,
}),
{
page: 1,
per_page: 10,
order: 'desc',
order_by: defaultOrderBy,
}
)
})
).toStrictEqual({
page: 1,
per_page: 10,
order: 'desc',
order_by: defaultOrderBy,
})
})
it('returns query updated', () => {
assert.deepEqual(
expect(
getQuery(
{ page: '3', per_page: '10', order: 'asc', order_by: 'workouts_count' },
orderByList,
defaultOrderBy,
{ query: inputQuery }
),
{ page: 3, per_page: 10, order: 'asc', order_by: 'workouts_count' }
)
)
).toStrictEqual({
page: 3,
per_page: 10,
order: 'asc',
order_by: 'workouts_count',
})
})
it('returns query with only pagination keys', () => {
assert.deepEqual(
expect(
getQuery(
{
page: '3',
@ -250,9 +246,13 @@ describe('getQuery w/ default values and input pagination payload', () => {
orderByList,
defaultOrderBy,
{ query: inputQuery }
),
{ page: 3, per_page: 10, order: 'asc', order_by: 'workouts_count' }
)
)
).toStrictEqual({
page: 3,
per_page: 10,
order: 'asc',
order_by: 'workouts_count',
})
})
})
@ -385,10 +385,9 @@ describe('rangePagination', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
rangePagination(testParams.input.pages, testParams.input.currentPage),
testParams.expectedPagination
)
expect(
rangePagination(testParams.input.pages, testParams.input.currentPage)
).toStrictEqual(testParams.expectedPagination)
})
})
})

View File

@ -1,4 +1,4 @@
import { assert, expect } from 'chai'
import { describe, it, expect } from 'vitest'
import {
getCalendarStartAndEnd,
@ -36,8 +36,7 @@ describe('startDate (week starting Sunday)', () => {
it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual(
getStartDate(testParams.inputDuration, day, false),
expect(getStartDate(testParams.inputDuration, day, false)).toStrictEqual(
expected
)
})
@ -70,8 +69,7 @@ describe('startDate (week starting Monday)', () => {
it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual(
getStartDate(testParams.inputDuration, day, true),
expect(getStartDate(testParams.inputDuration, day, true)).toStrictEqual(
expected
)
})
@ -133,7 +131,9 @@ describe('dateIncrement', () => {
it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual(incrementDate(testParams.inputDuration, day), expected)
expect(incrementDate(testParams.inputDuration, day)).toStrictEqual(
expected
)
})
)
})
@ -173,8 +173,10 @@ describe('getCalendarStartAndEnd', () => {
date,
testParams.inputWeekStartingMonday
)
assert.deepEqual(results.start, new Date(testParams.expectedStartDate))
assert.deepEqual(results.end, new Date(testParams.expectedEndDate))
expect(results.start).toStrictEqual(
new Date(testParams.expectedStartDate)
)
expect(results.end).toStrictEqual(new Date(testParams.expectedEndDate))
})
)
})
@ -232,14 +234,13 @@ describe('formatWorkoutDate', () => {
]
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
formatWorkoutDate(
testParams.inputParams.date,
testParams.inputParams.dateFormat,
testParams.inputParams.timeFormat
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -271,31 +272,29 @@ describe('formatDate', () => {
]
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
formatDate(
dateString,
testParams.inputParams.timezone,
testParams.inputParams.dateFormat,
testParams.inputParams.withTime
),
testParams.expectedDate
)
)
).toStrictEqual(testParams.expectedDate)
})
})
})
describe('formatDate (w/ default value)', () => {
it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format', () => {
assert.deepEqual(
formatDate('Tue, 01 Nov 2022 00:00:00 GMT', 'Europe/Paris', 'yyyy-MM-dd'),
'2022-11-01 01:00'
)
expect(
formatDate('Tue, 01 Nov 2022 00:00:00 GMT', 'Europe/Paris', 'yyyy-MM-dd')
).toBe('2022-11-01 01:00')
})
})
describe('formatDate with_seconds', () => {
it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format and seconds', () => {
assert.deepEqual(
expect(
formatDate(
'Tue, 01 Nov 2022 00:00:00 GMT',
'Europe/Paris',
@ -303,9 +302,8 @@ describe('formatDate with_seconds', () => {
true,
null,
true
),
'2022-11-01 01:00:00'
)
)
).toBe('2022-11-01 01:00:00')
})
})
@ -356,13 +354,12 @@ describe('getDateFormat', () => {
]
testsParams.map((testParams) => {
it(`get date format for "${testParams.inputParams.language}" and "${testParams.inputParams.dateFormat}" `, () => {
assert.deepEqual(
expect(
getDateFormat(
testParams.inputParams.dateFormat,
testParams.inputParams.language
),
testParams.expectedFormat
)
)
).toBe(testParams.expectedFormat)
})
})
})
@ -403,14 +400,13 @@ describe('availableDateFormatOptions', () => {
testsParams.map((testParams) => {
it(`returns available options for ${testParams.inputLanguage} locale`, () => {
assert.deepEqual(
expect(
availableDateFormatOptions(
inputDate,
inputTimezone,
testParams.inputLanguage
),
testParams.expectedOptions
)
)
).toStrictEqual(testParams.expectedOptions)
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { formatDuration } from '@/utils/duration'
@ -43,8 +43,7 @@ describe('formatDuration (without days)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
formatDuration(testParams.inputDuration),
expect(formatDuration(testParams.inputDuration)).toStrictEqual(
testParams.expectedDuration
)
})
@ -92,8 +91,7 @@ describe('formatDuration (with days)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
formatDuration(testParams.inputDuration, true),
expect(formatDuration(testParams.inputDuration, true)).toStrictEqual(
testParams.expectedDuration
)
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { getFileSizeInMB, getReadableFileSize } from '@/utils/files'
@ -23,8 +23,7 @@ describe('getReadableFileSize (as text)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
getReadableFileSize(testParams.inputFileSize, true),
expect(getReadableFileSize(testParams.inputFileSize, true)).toStrictEqual(
testParams.expectedReadableFileSize
)
})
@ -52,10 +51,9 @@ describe('getReadableFileSize (as object)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
getReadableFileSize(testParams.inputFileSize, false),
testParams.expectedReadableFileSize
)
expect(
getReadableFileSize(testParams.inputFileSize, false)
).toStrictEqual(testParams.expectedReadableFileSize)
})
})
})
@ -81,8 +79,7 @@ describe('getFileSizeInMB', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
getFileSizeInMB(testParams.inputFileSize),
expect(getFileSizeInMB(testParams.inputFileSize)).toStrictEqual(
testParams.expectedFileSize
)
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { linkifyAndClean } from '@/utils/inputs'
@ -11,15 +11,14 @@ describe('linkifyAndClean (clean input remains unchanged)', () => {
testInputs.map((testInput) => {
it(`it returns unmodified input: '${testInput}'`, () => {
assert.equal(linkifyAndClean(testInput), testInput)
expect(linkifyAndClean(testInput)).toBe(testInput)
})
})
})
describe('linkifyAndClean (URL is linkified)', () => {
it('it returns URL as link with target blank', () => {
assert.equal(
linkifyAndClean('link: http://www.example.com'),
expect(linkifyAndClean('link: http://www.example.com')).toBe(
'link: <a href="http://www.example.com" target="_blank">http://www.example.com</a>'
)
})
@ -62,8 +61,7 @@ describe('linkifyAndClean (input sanitization)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
linkifyAndClean(testParams.inputString),
expect(linkifyAndClean(testParams.inputString)).toBe(
testParams.expectedString
)
})

View File

@ -1,4 +1,4 @@
import { assert, expect } from 'chai'
import { describe, it, expect } from 'vitest'
import { translatedSports } from './fixtures'
@ -19,7 +19,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 9,
@ -42,7 +42,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/MM/dd'
date_format: 'yyyy/MM/dd',
},
expected: {
id: 10,
@ -65,7 +65,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/MM/dd'
date_format: 'yyyy/MM/dd',
},
expected: {
id: 11,
@ -88,7 +88,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'dd/MM/yyyy'
date_format: 'dd/MM/yyyy',
},
expected: {
id: 12,
@ -111,7 +111,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'MMM. do, yyyy'
date_format: 'MMM. do, yyyy',
},
expected: {
id: 13,
@ -124,15 +124,14 @@ describe('formatRecord', () => {
]
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
formatRecord(
testParams.inputParams.record,
testParams.inputParams.timezone,
false,
testParams.inputParams.date_format
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -152,7 +151,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 9,
@ -175,7 +174,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 10,
@ -198,7 +197,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 11,
@ -221,7 +220,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 12,
@ -244,7 +243,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
},
timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
id: 13,
@ -257,15 +256,14 @@ describe('formatRecord after conversion', () => {
]
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
formatRecord(
testParams.inputParams.record,
testParams.inputParams.timezone,
true,
testParams.inputParams.date_format
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -300,7 +298,7 @@ describe('getRecordsBySports', () => {
input: {
records: [],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {},
},
@ -319,7 +317,7 @@ describe('getRecordsBySports', () => {
},
],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
'Cycling (Sport)': {
@ -370,7 +368,7 @@ describe('getRecordsBySports', () => {
},
],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
'Cycling (Sport)': {
@ -411,7 +409,7 @@ describe('getRecordsBySports', () => {
]
testsParams.map((testParams) =>
it(testParams.description, () => {
assert.deepEqual(
expect(
getRecordsBySports(
testParams.input.records,
translatedSports,
@ -419,11 +417,8 @@ describe('getRecordsBySports', () => {
false,
true,
testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
)
})
@ -435,7 +430,7 @@ describe('getRecordsBySports after conversion', () => {
input: {
records: [],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {},
},
@ -454,7 +449,7 @@ describe('getRecordsBySports after conversion', () => {
},
],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
'Cycling (Sport)': {
@ -505,7 +500,7 @@ describe('getRecordsBySports after conversion', () => {
},
],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
'Cycling (Sport)': {
@ -546,7 +541,7 @@ describe('getRecordsBySports after conversion', () => {
]
testsParams.map((testParams) =>
it(testParams.description, () => {
assert.deepEqual(
expect(
getRecordsBySports(
testParams.input.records,
translatedSports,
@ -554,11 +549,8 @@ describe('getRecordsBySports after conversion', () => {
true,
true,
testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
)
})
@ -570,7 +562,7 @@ describe('getRecordsBySports with HA record', () => {
input: {
records: [],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {},
},
@ -598,7 +590,7 @@ describe('getRecordsBySports with HA record', () => {
},
],
tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM'
date_format: 'yyyy/dd/MM',
},
expected: {
'Cycling (Sport)': {
@ -619,7 +611,7 @@ describe('getRecordsBySports with HA record', () => {
]
testsParams.map((testParams) =>
it(testParams.description, () => {
assert.deepEqual(
expect(
getRecordsBySports(
testParams.input.records,
translatedSports,
@ -627,11 +619,8 @@ describe('getRecordsBySports with HA record', () => {
false,
false,
testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
)
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { sports } from './fixtures'
@ -451,15 +451,14 @@ describe('translateSports', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
locale.value = testParams.inputParams.locale
assert.deepEqual(
expect(
translateSports(
testParams.inputParams.sports,
t,
testParams.inputParams.activeStatus,
testParams.inputParams.sportsToInclude
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { sports } from './fixtures'
@ -87,7 +87,7 @@ describe('getDateKeys (week starting Sunday)', () => {
const expected: Date[] = testParams.expected.map(
(date_string: string) => new Date(date_string)
)
assert.deepEqual(getDateKeys(testParams.inputParams, false), expected)
expect(getDateKeys(testParams.inputParams, false)).toStrictEqual(expected)
})
)
})
@ -162,7 +162,7 @@ describe('getDateKeys (week starting Monday)', () => {
const expected: Date[] = testParams.expected.map(
(date_string: string) => new Date(date_string)
)
assert.deepEqual(getDateKeys(testParams.inputParams, true), expected)
expect(getDateKeys(testParams.inputParams, true)).toStrictEqual(expected)
})
)
})
@ -282,8 +282,9 @@ describe('getDatasets', () => {
},
],
}
assert.deepEqual(getDatasets(sports), expected)
expect(getDatasets(sports)).toStrictEqual(expected)
})
it('returns chart datasets with only displayed sports', () => {
const expected: TStatisticsDatasets = {
average_speed: [
@ -332,7 +333,7 @@ describe('getDatasets', () => {
},
],
}
assert.deepEqual(getDatasets([sports[1]]), expected)
expect(getDatasets([sports[1]])).toStrictEqual(expected)
})
})
@ -355,7 +356,7 @@ describe('formatStats', () => {
total_descent: [],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -364,9 +365,8 @@ describe('formatStats', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it('returns empty datasets if no data and displayed sport provided', () => {
@ -426,7 +426,7 @@ describe('formatStats', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -435,9 +435,8 @@ describe('formatStats', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it('returns empty datasets if data provided but no displayed sport', () => {
@ -497,7 +496,7 @@ describe('formatStats', () => {
total_descent: [],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -506,9 +505,8 @@ describe('formatStats', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it('returns datasets when data and displayed sport provided', () => {
@ -607,7 +605,7 @@ describe('formatStats', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -616,9 +614,8 @@ describe('formatStats', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
})
@ -719,7 +716,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -728,9 +725,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it("returns datasets when duration is 'month'", () => {
const inputStats: TStatisticsFromApi = {
@ -828,7 +824,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -837,9 +833,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it("returns datasets when duration is 'week' and week starts on Sunday", () => {
@ -938,7 +933,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -947,9 +942,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it("returns datasets when duration is 'week' and week starts on Monday", () => {
@ -1048,7 +1042,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
true,
@ -1057,9 +1051,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it("returns datasets when duration is 'week' and date format 'dd/MM/yyyy'", () => {
@ -1158,7 +1151,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -1167,9 +1160,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'dd/MM/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
it("returns datasets when duration is 'week' and date format is 'date_string'", () => {
@ -1269,7 +1261,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -1278,9 +1270,8 @@ describe('formatStats (duration)', () => {
inputStats,
false,
'date_string'
),
expected
)
)
).toStrictEqual(expected)
})
it('returns datasets after conversion to imperial units', () => {
@ -1379,7 +1370,7 @@ describe('formatStats (duration)', () => {
],
},
}
assert.deepEqual(
expect(
formatStats(
inputParams,
false,
@ -1388,9 +1379,8 @@ describe('formatStats (duration)', () => {
inputStats,
true,
'MM/dd/yyyy'
),
expected
)
)
).toStrictEqual(expected)
})
})
@ -1425,14 +1415,9 @@ describe("getStatsDateParams when time frame is 'month')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
getStatsDateParams(
testParams.input.date,
'month',
weekStartingMonday
),
testParams.expected
)
expect(
getStatsDateParams(testParams.input.date, 'month', weekStartingMonday)
).toStrictEqual(testParams.expected)
})
})
})
@ -1469,10 +1454,9 @@ describe("getStatsDateParams when time frame is 'year')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
getStatsDateParams(testParams.input.date, 'year', weekStartingMonday),
testParams.expected
)
expect(
getStatsDateParams(testParams.input.date, 'year', weekStartingMonday)
).toStrictEqual(testParams.expected)
})
})
})
@ -1537,14 +1521,13 @@ describe("getStatsDateParams when time frame is 'week')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
getStatsDateParams(
testParams.input.date,
'week',
testParams.input.weekStartingMonday
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -1626,14 +1609,13 @@ describe("updateChartParams when time frame is 'month')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
updateChartParams(
testParams.input.chartParams,
testParams.input.backward,
weekStartingMonday
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -1712,14 +1694,13 @@ describe("updateChartParams when time frame is 'year')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
updateChartParams(
testParams.input.chartParams,
testParams.input.backward,
weekStartingMonday
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -1803,14 +1784,13 @@ describe("updateChartParams when time frame is 'week')", () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.deepEqual(
expect(
updateChartParams(
testParams.input.chartParams,
testParams.input.backward,
testParams.input.weekStartingMonday
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { datasetKeys } from '@/utils/statistics'
import { formatTooltipValue } from '@/utils/tooltip'
@ -45,14 +45,13 @@ describe('formatTooltipValue', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
false
),
testParams.expectedResult
)
)
).toStrictEqual(testParams.expectedResult)
})
})
})
@ -99,14 +98,13 @@ describe('formatTooltipValue after conversion to imperial units', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
true
),
testParams.expectedResult
)
)
).toStrictEqual(testParams.expectedResult)
})
})
})
@ -145,16 +143,15 @@ describe('formatTooltipValue with unitFrom', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
testParams.useImperialUnits,
true,
'm'
),
testParams.expectedResult
)
)
).toStrictEqual(testParams.expectedResult)
})
})
})
@ -201,15 +198,14 @@ describe('formatTooltipValue (formatWithUnits = false)', () => {
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
false,
false
),
testParams.expectedResult
)
)
).toStrictEqual(testParams.expectedResult)
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { TUnit } from '@/types/units'
import { convertDistance, getTemperature, getWindSpeed } from '@/utils/units'
@ -26,8 +26,7 @@ describe('convertDistance', () => {
testsParams.map((testParams) => {
it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => {
assert.equal(
convertDistance(testParams[0], testParams[1], testParams[2]),
expect(convertDistance(testParams[0], testParams[1], testParams[2])).toBe(
testParams[3]
)
})
@ -44,15 +43,14 @@ describe('convertDistance w/ digits', () => {
testsParams.map((testParams) => {
it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => {
assert.equal(
expect(
convertDistance(
testParams[0],
testParams[1],
testParams[2],
testParams[3]
),
testParams[4]
)
)
).toBe(testParams[4])
})
})
})
@ -68,7 +66,7 @@ describe('getTemperature', () => {
testsParams.map((testParams) => {
it(`get temperature for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => {
assert.equal(getTemperature(testParams[0], testParams[1]), testParams[2])
expect(getTemperature(testParams[0], testParams[1])).toBe(testParams[2])
})
})
})
@ -84,7 +82,7 @@ describe('getWindSpeed', () => {
testsParams.map((testParams) => {
it(`get wind speed for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => {
assert.equal(getWindSpeed(testParams[0], testParams[1]), testParams[2])
expect(getWindSpeed(testParams[0], testParams[1])).toBe(testParams[2])
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import { convertDegreeToDirection } from '@/utils/weather'
@ -17,7 +17,7 @@ describe('convertDegreeToDirection', () => {
]
testsParams.map((testParams) => {
it(`convert ${testParams[0]}° to ${testParams[1]}`, () => {
assert.equal(convertDegreeToDirection(testParams[0]), testParams[1])
expect(convertDegreeToDirection(testParams[0])).toBe(testParams[1])
})
})
})

View File

@ -1,4 +1,4 @@
import { assert } from 'chai'
import { describe, it, expect } from 'vitest'
import createI18n from '@/i18n'
import { getDatasets, getDonutDatasets } from '@/utils/workouts'
@ -172,14 +172,13 @@ describe('getDatasets', () => {
testparams.map((testParams) => {
it(testParams.description, () => {
locale.value = testParams.inputParams.locale
assert.deepEqual(
expect(
getDatasets(
testParams.inputParams.charData,
t,
testParams.inputParams.useImperialUnits
),
testParams.expected
)
)
).toStrictEqual(testParams.expected)
})
})
})
@ -329,9 +328,9 @@ describe('getDonutDatasets', () => {
]
testparams.map((testParams) => {
it(testParams.description, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
assert.deepEqual(getDonutDatasets(testParams.input), testParams.expected)
expect(getDonutDatasets(testParams.input)).toStrictEqual(
testParams.expected
)
})
})
})

View File

@ -6,6 +6,9 @@
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
],
"compilerOptions": {

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": ["node", "jsdom"]
}
}

View File

@ -0,0 +1,14 @@
import { fileURLToPath } from 'node:url'
import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
},
})
)

File diff suppressed because it is too large Load Diff