Skip to content

Commit d114e6c

Browse files
committed
refactor: remove fs-cheerio
1 parent 7cd1726 commit d114e6c

8 files changed

+16
-48
lines changed

Diff for: .babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/env"]
3+
}

Diff for: __tests__/page-loader.test.js

-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import os from 'os';
44
import fs from 'fs/promises';
55
import path from 'path';
66
import nock from 'nock';
7-
import process from 'process';
87
import cheerio from 'cheerio';
98
import { readFile, getFixturePath, trimHtml } from '../test-helpers.js';
109
import { loadPage } from '../page-loader.js';
@@ -46,22 +45,6 @@ describe('downloads html', () => {
4645
expect(trimHtml(actualContent)).toBe(html);
4746
expect(returnValue.filepath).toBe(expectedFilePath);
4847
});
49-
50-
test('to the current working directory, if the destFolder parameter is not defined', async () => {
51-
const cwdMock = jest.spyOn(process, 'cwd');
52-
cwdMock.mockImplementation(() => tmpFolder);
53-
54-
const returnValue = await loadPage('https://ru.hexlet.io/courses');
55-
56-
const expectedFilePath = path.join(tmpFolder, 'ru-hexlet-io-courses.html');
57-
58-
const actualContent = await fs.readFile(expectedFilePath, 'utf-8');
59-
60-
expect(trimHtml(actualContent)).toBe(trimHtml(html));
61-
expect(returnValue.filepath).toBe(expectedFilePath);
62-
63-
cwdMock.mockRestore();
64-
});
6548
});
6649

6750
describe('downloads local resources', () => {

Diff for: babel.config.cjs

-3
This file was deleted.

Diff for: cli.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/usr/bin/env node
22

3+
import program from 'commander';
34
import { loadPage } from './page-loader.js';
4-
import { program } from 'commander';
55

6-
program.option('-o, --output <path>', 'output path');
7-
program.parse(process.argv);
6+
program
7+
.description('Loads page')
8+
.arguments('<pageUrl>')
9+
.option('-o, --output [path]', 'choose output path', process.cwd())
10+
.action(async (pageUrl, options) => {
11+
console.log(await loadPage(pageUrl, options.output));
12+
})
13+
.parse(process.argv);
814

9-
const options = program.opts();
10-
const { output } = options;
11-
const { args } = program;
12-
13-
loadPage(args[0], output);
15+
if (!program.args.length) program.help();

Diff for: jest.config.cjs

-5
This file was deleted.

Diff for: package-lock.json

+1-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "@hexlet/code",
3-
"type": "module",
43
"version": "1.0.0",
54
"description": "[![Actions Status](https://github.com/nowaylifer/frontend-testing-react-project-67/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/nowaylifer/frontend-testing-react-project-67/actions)",
65
"main": "page-loader.js",
@@ -33,7 +32,6 @@
3332
"cheerio": "^1.0.0-rc.12",
3433
"commander": "^11.0.0",
3534
"debug": "^4.3.4",
36-
"fs-cheerio": "^3.0.0",
3735
"mime-types": "^2.1.35"
3836
}
3937
}

Diff for: page-loader.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import path from 'path';
44
import fs from 'fs/promises';
55
import process from 'process';
66
import cheerio from 'cheerio';
7-
import fsc from 'fs-cheerio';
87
import mime from 'mime-types';
98
import { createWriteStream } from 'fs';
109

@@ -17,7 +16,7 @@ class PageLoader {
1716
#outputDir;
1817
#resourceDir;
1918

20-
constructor(urlString, outputDir = process.cwd()) {
19+
constructor(urlString, outputDir) {
2120
this.#url = new URL(urlString);
2221
this.#outputDir = this.#normalizeDirPath(outputDir);
2322
this.#resourceDir = `${this.#generateFileName(this.#url.href)}_files`;
@@ -38,7 +37,7 @@ class PageLoader {
3837
const htmlFilename = this.#generateFileName(this.#url.href) + '.html';
3938
const filepath = path.join(this.#outputDir, htmlFilename);
4039

41-
await fsc.writeFile(filepath, $);
40+
await fs.writeFile(filepath, $.html());
4241

4342
return filepath;
4443
}

0 commit comments

Comments
 (0)