Skip to content

update tests #10

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 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM hexletbasics/base-image

WORKDIR /exercises-pre-course-javascript

COPY . .

ENV NODE_PATH /exercises-pre-course-javascript/src

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / main

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV PATH=/exercises-pre-course-javascript/bin:$PATH

WORKDIR /exercises-pre-course-javascript

RUN npm i -g vitest
COPY package.json package-lock.json ./
RUN npm ci

ENV PATH=/exercises-pre-course-javascript/bin:$PATH
COPY . .
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.js
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-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/10-basics/10-hello-world/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// @ts-check

import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'Hello, World!';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/10-basics/20-comments/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
2 changes: 1 addition & 1 deletion modules/10-basics/40-instructions/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/10-basics/40-instructions/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// @ts-check

import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'Robert\nStannis\nRenly';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/10-basics/45-testing/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/10-basics/45-testing/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '9780262531962';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/10-basics/50-syntax-errors/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/10-basics/50-syntax-errors/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'What Is Dead May Never Die';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/20-basic/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/20-basic/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '9';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/25-operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/25-operator/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '87';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/27-commutativity/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/27-commutativity/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '243\n2';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

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.

У нас это уже выделено отдельно

const expectOutput = async (expected, run = (f) => f()) => {
но не работает на витесте, падает ошибка и пока с ней разобраться не удается, уже много времени на это потратил. Конечно могу это вынести. Думаю можно это даже попробовать через конфиг витеста сделать

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/30-composition/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/30-composition/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '10.5';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/40-priority/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/40-priority/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '49';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/50-float/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/50-float/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 0.39 * 0.22;
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls[0]?.[0];

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/60-infinity/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/60-infinity/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = Infinity;
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls[0]?.[0];

Copy link
Contributor

Choose a reason for hiding this comment

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

А в чем отличие от const firstArg = consoleLogSpy.mock.calls.join('\n');?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Здесь берем именно что было передано в первый вызов console.log. при чем получаем не строковое значение, а тот тип, который был передан

Copy link
Contributor

Choose a reason for hiding this comment

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

окей, понял, вижу что в хелоу ворлде так сделано

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/70-nan/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/70-nan/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'NaN';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/20-arithmetics/80-linting/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/20-arithmetics/80-linting/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '4';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/25-strings/10-quotes/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/25-strings/10-quotes/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = "\"Khal Drogo's favorite word is \"athjahakar\"\"";
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/25-strings/15-escape-characters/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/25-strings/15-escape-characters/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '- Did Joffrey agree?\n- He did. He also said "I love using \\n".';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/25-strings/20-string-concatenation/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/25-strings/20-string-concatenation/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'Winter came for the House of Frey.';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/25-strings/30-encoding/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/25-strings/30-encoding/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = '~\n^\n%';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/30-variables/10-definition/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/30-variables/10-definition/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'What Is Dead May Never Die!';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/30-variables/11-change/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
12 changes: 10 additions & 2 deletions modules/30-variables/11-change/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { expectOutput } from 'hexlet-basics/tests';
import { expect, test, vi } from 'vitest'

const expected = 'anneirB';
expectOutput(expected);

test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
await import('./index.js')

const firstArg = consoleLogSpy.mock.calls.join('\n');

expect(firstArg).toBe(expected)
})
2 changes: 1 addition & 1 deletion modules/30-variables/13-variables-naming/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
@ test-output.sh
@ test2.sh
Loading
Loading