Skip to content

Commit 7cd1726

Browse files
committed
fix: change bin script
1 parent a26a8b9 commit 7cd1726

7 files changed

+23
-14
lines changed

__tests__/page-loader.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import fs from 'fs/promises';
55
import path from 'path';
66
import nock from 'nock';
77
import process from 'process';
8-
import * as cheerio from 'cheerio';
9-
import { readFile, getFixturePath, trimHtml } from '../test-helpers';
10-
import { loadPage } from '../page-loader';
8+
import cheerio from 'cheerio';
9+
import { readFile, getFixturePath, trimHtml } from '../test-helpers.js';
10+
import { loadPage } from '../page-loader.js';
1111

1212
let tmpFolder;
1313

babel.config.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current', esmodules: true } }]],
3+
};

babel.config.json

-3
This file was deleted.

jest.config.cjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
transform: {
3+
'^.+\\.(js|jsx)$': 'babel-jest',
4+
},
5+
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"type": "module",
44
"version": "1.0.0",
55
"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)",
6-
"main": "index.js",
6+
"main": "page-loader.js",
77
"scripts": {
88
"test": "jest --runInBand",
99
"test:log-nock": "DEBUG=nock.* jest --runInBand",
1010
"test:log-axios": "DEBUG=axios jest --runInBand",
1111
"test:log": "DEBUG=page-loader jest --runInBand"
1212
},
1313
"bin": {
14-
"page-loader": "babel-node cli.js"
14+
"page-loader": "cli.js"
1515
},
1616
"keywords": [],
1717
"author": "",

page-loader.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios';
33
import path from 'path';
44
import fs from 'fs/promises';
55
import process from 'process';
6-
import * as cheerio from 'cheerio';
6+
import cheerio from 'cheerio';
77
import fsc from 'fs-cheerio';
88
import mime from 'mime-types';
99
import { createWriteStream } from 'fs';
@@ -12,7 +12,7 @@ const debug = setNamespace('page-loader');
1212

1313
let $;
1414

15-
export class PageLoader {
15+
class PageLoader {
1616
#url;
1717
#outputDir;
1818
#resourceDir;
@@ -96,7 +96,6 @@ export class PageLoader {
9696
const { url } = resp.config;
9797
const extname = path.extname(url) || `.${mime.extension(resp.headers['content-type'])}`;
9898
const resourcePath = this.#getResourceFilePath(url, extname);
99-
console.log(resourcePath);
10099

101100
this.#changeElementUrl(el, resourcePath);
102101

@@ -171,6 +170,11 @@ export class PageLoader {
171170
}
172171
}
173172

174-
export const loadPage = (url, destFolder) => {
173+
const loadPage = (url, destFolder) => {
175174
return new PageLoader(url, destFolder).load();
176175
};
176+
177+
module.exports = {
178+
PageLoader,
179+
loadPage,
180+
};

test-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const path = require('path');
2-
const fs = require('fs/promises');
1+
import path from 'path';
2+
import fs from 'fs/promises';
33

44
const getFixturePath = (filename) => path.join(__dirname, '__fixtures__', filename);
55
const readFile = (filename) => fs.readFile(getFixturePath(filename), 'utf-8');

0 commit comments

Comments
 (0)