Skip to content

Commit 2ccb468

Browse files
committed
Test negative cases refactoring
1 parent 4d41ae0 commit 2ccb468

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed
Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1-
<!DOCTYPE html>
2-
<html lang="ru">
3-
<head>
4-
<meta charset="utf-8" />
1+
<!DOCTYPE html><html lang="ru"><head>
2+
<meta charset="utf-8">
53
<title>Курсы по программированию Хекслет</title>
6-
<link
7-
rel="stylesheet"
8-
media="all"
9-
href="https://cdn2.hexlet.io/assets/menu.css"
10-
/>
11-
<link
12-
rel="stylesheet"
13-
media="all"
14-
href="ru-hexlet-io-courses_files/ru-hexlet-io-assets-application.css"
15-
/>
16-
<link
17-
href="ru-hexlet-io-courses_files/ru-hexlet-io-courses.html"
18-
rel="canonical"
19-
/>
4+
<link rel="stylesheet" media="all" href="https://cdn2.hexlet.io/assets/menu.css">
5+
<link rel="stylesheet" media="all" href="ru-hexlet-io-courses_files/ru-hexlet-io-assets-application.css">
6+
<link href="ru-hexlet-io-courses_files/ru-hexlet-io-courses.html" rel="canonical">
207
</head>
218
<body>
22-
<img
23-
src="ru-hexlet-io-courses_files/ru-hexlet-io-assets-professions-nodejs.png"
24-
alt="Иконка профессии Node.js-программист"
25-
/>
9+
<img src="ru-hexlet-io-courses_files/ru-hexlet-io-assets-professions-nodejs.png" alt="Иконка профессии Node.js-программист">
2610
<h3>
2711
<a href="/professions/nodejs">Node.js-программист</a>
2812
</h3>
2913
<script src="https://js.stripe.com/v3/"></script>
3014
<script src="ru-hexlet-io-courses_files/ru-hexlet-io-packs-js-runtime.js"></script>
31-
</body>
32-
</html>
15+
16+
17+
</body></html>

__tests__/page-loader.test.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,45 @@ test('page-loader', async () => {
5959
expect(downloadedScript).toBe('js {}')
6060
})
6161

62-
test('page-loader: network errors', async () => {
63-
nock('https://ru.hexlet.io')
64-
.get('/courses')
65-
.reply(404)
66-
nock('https://ru.hexlet.io')
67-
.get('/assets/professions/nodejs.png')
68-
.reply(500)
62+
const networkErrors = [
63+
{
64+
url: 'https://ru.hexlet.io/courses',
65+
status: 404,
66+
expected: 'Cant get https://ru.hexlet.io/courses - Request failed with status code 404',
67+
},
68+
{
69+
url: 'https://ru.hexlet.io/assets/professions/nodejs.png',
70+
status: 500,
71+
expected: 'Cant get https://ru.hexlet.io/assets/professions/nodejs.png - Request failed with status code 500',
72+
},
73+
]
6974

70-
await expect(downloadPage('https://ru.hexlet.io/courses', tempDir))
71-
.rejects
72-
.toThrow('Cant get https://ru.hexlet.io/courses - Request failed with status code 404')
73-
await expect(downloadPage('https://ru.hexlet.io/assets/professions/nodejs.png', tempDir))
74-
.rejects
75-
.toThrow('Cant get https://ru.hexlet.io/assets/professions/nodejs.png - Request failed with status code 500')
76-
})
75+
test.each(networkErrors)('page-loader: network error $status',
76+
async ({ url, status, expected }) => {
77+
nock('https://ru.hexlet.io')
78+
.get(new URL(url).pathname)
79+
.reply(status)
7780

78-
test('page-loader: file operation errors', async () => {
79-
nock('https://ru.hexlet.io')
80-
.get('/courses')
81-
.times(2)
82-
.reply(200, html)
81+
await expect(downloadPage(url, tempDir)).rejects.toThrow(expected)
82+
})
8383

84-
await expect(downloadPage('https://ru.hexlet.io/courses', '/unexisting'))
85-
.rejects.toThrow('ERROR: No such output directory - /unexisting')
86-
await expect(downloadPage('https://ru.hexlet.io/courses', '/root'))
87-
.rejects.toThrow('ERROR: No access to output directory - /root')
88-
})
84+
const fileErrors = [
85+
{
86+
path: '/unexisting',
87+
expected: 'ERROR: No such output directory - /unexisting',
88+
},
89+
{
90+
path: '/root',
91+
expected: 'ERROR: No access to output directory - /root',
92+
},
93+
]
94+
95+
test.each(fileErrors)('page-loader: file operation error on path $path',
96+
async ({ path, expected }) => {
97+
nock('https://ru.hexlet.io')
98+
.get('/courses')
99+
.reply(200, html)
100+
101+
await expect(downloadPage('https://ru.hexlet.io/courses', path))
102+
.rejects.toThrow(expected)
103+
})

0 commit comments

Comments
 (0)