Skip to content

Vitest exerices #319

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
Mar 10, 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
18 changes: 8 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
FROM hexletbasics/base-image:latest

WORKDIR /exercises-typescript

COPY package.json .
ENV PATH=/exercises-typescript/bin:/exercises-typescript/node_modules/.bin:$PATH
# ENV NODE_OPTIONS --max-old-space-size=4096
# --experimental-vm-modules
ENV CI=true

COPY package-lock.json .
WORKDIR /exercises-typescript

RUN npm install
RUN npm i -g vitest
Copy link
Contributor

Choose a reason for hiding this comment

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

@dzencot почему не ставим как зависимость?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Он вызывается глобально в скрипте bin/test2.sh. Не знаю почему так сделано, можно и в локальные зависимости перенести. Я просто скопировал из js. Но давай в локальную переделаю отдельным пр, чтобы сразу во всех стеках было

COPY package.json package-lock.json ./
RUN npm ci

COPY . .

ENV PATH /exercises-typescript/bin:/exercises-typescript/node_modules/.bin:$PATH
# ENV NODE_OPTIONS --max-old-space-size=4096
# --experimental-vm-modules
ENV CI true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ ci-check:
docker compose --file docker-compose.yml up --abort-on-container-exit

test-fast:
npx jest
npx vitest
3 changes: 3 additions & 0 deletions bin/test2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

FORCE_COLOR=1 vitest related --run `pwd`/test.ts
12 changes: 12 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";


/** @type {import('eslint').Linter.Config[]} */
export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion modules/10-basics/10-hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
7 changes: 4 additions & 3 deletions modules/10-basics/10-hello-world/test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test, vi } from 'vitest'
import * as path from 'path';
import * as sinon from 'sinon';

test('hello world', async () => {
const spy = sinon.spy(console, 'log');
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import(path.join(__dirname, 'index'));
sinon.assert.calledWith(spy, 'Hello, World!');
const firstArg = consoleLogSpy.mock.calls[0]?.[0];
expect(firstArg).toBe('Hello, World!')
});
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

// BEGIN
function multiply(a: number, b: number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import multiply from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/30-variables/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
2 changes: 1 addition & 1 deletion modules/10-basics/30-variables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

function repeat(text: string, count: number) {
// BEGIN
Expand Down
1 change: 1 addition & 0 deletions modules/10-basics/30-variables/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import repeat from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/40-named-functions/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/40-named-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import getHiddenCard from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/45-anonymous-functions/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/45-anonymous-functions/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import getEvenNumbers from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/50-arrays/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/50-arrays/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import filterAnagrams from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/55-objects/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/55-objects/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import isComplete from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/60-enums/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/60-enums/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import buildModal, { ModalStatus } from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/70-type-aliases/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/70-type-aliases/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import getOlderUser, { User } from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/80-any/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
6 changes: 3 additions & 3 deletions modules/10-basics/80-any/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-explicit-any */

// BEGIN
Expand Down
1 change: 1 addition & 0 deletions modules/10-basics/80-any/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import getParams from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/10-basics/90-modules/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/10-basics/90-modules/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import authorize from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/10-function-as-parameter/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/10-function-as-parameter/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import filter from './index';

test('function', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

// BEGIN
function map(numbers: number[], callback: (n: number, index: number) => number): number[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import map from './index';

test('map', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/30-void/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
2 changes: 1 addition & 1 deletion modules/20-functions/30-void/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect, test } from 'vitest'
import forEach from './index';

test('forEach', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/35-never/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/35-never/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import fail from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/40-unknown/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/40-unknown/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import isPlainObject from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/70-destructuring/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/70-destructuring/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import lessonsCount from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/80-rest-spread/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/80-rest-spread/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import max from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/85-function-overloads/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
2 changes: 1 addition & 1 deletion modules/20-functions/85-function-overloads/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */

// BEGIN
function newYearCongratulate(name: string): string;
Expand Down
1 change: 1 addition & 0 deletions modules/20-functions/85-function-overloads/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import sayHello from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/20-functions/90-type-narrowing/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/20-functions/90-type-narrowing/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import last from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/22-arrays/20-type-annotations/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/22-arrays/20-type-annotations/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import unique from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/22-arrays/25-multi-dimensional-arrays/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/22-arrays/25-multi-dimensional-arrays/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import getField from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/22-arrays/40-readonly-arrays/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/22-arrays/40-readonly-arrays/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import reverse from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/22-arrays/50-tuples/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/22-arrays/50-tuples/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import isTheSamePoint, { Point } from './index';

test('function', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/10-type-as-sets/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/10-type-as-sets/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import type CustomType from './index';

test('CustomType', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/20-union-types/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/20-union-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import lastIndex from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/22-nullable/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/22-nullable/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import formatPrice from './index';

test('formatPrice', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/25-literal-types/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/25-literal-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import startGame from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/30-intersection-types/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/30-intersection-types/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import addAdmin, { User, Permission } from './index';

test('addAdmin', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/40-assignability/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/40-assignability/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ta from 'type-assertions';
import { expect, test } from 'vitest';

import form from './index';

Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/50-type-hierarcy/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/50-type-hierarcy/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import getUserFriends, { UserResponse } from './index';

test('getUserFriends', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/25-types/60-structural-typing/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test.sh
@ test2.sh
1 change: 1 addition & 0 deletions modules/25-types/60-structural-typing/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest'
import handleData, { DataState, LoadingStatus } from './index';

test('handleData', () => {
Expand Down
Loading