Skip to content

Commit

Permalink
Remove deprecated exports (#3974)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Aug 6, 2024
1 parent c07bbf0 commit d4eb8d3
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 412 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ updates:
interval: daily
open-pull-requests-limit: 4
versioning-strategy: increase
# TODO: We cannot update React to v18. See https://github.com/facebook/docusaurus/issues/7264
ignore:
- dependency-name: 'react'
versions: ['18.x']
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
[中文文档 (Chinese Readme)](https://github.com/cheeriojs/cheerio/wiki/Chinese-README)

```js
const cheerio = require('cheerio');
import * as cheerio from 'cheerio';
const $ = cheerio.load('<h2 class="title">Hello world</h2>');

$('h2.title').text('Hello there!');
Expand Down Expand Up @@ -61,7 +61,7 @@ jQuery operates on the one, baked-in DOM. With Cheerio, we need to pass in the
HTML document.

```js
// ES6 or TypeScript:
// ESM or TypeScript:
import * as cheerio from 'cheerio';

// In other environments:
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Element } from 'domhandler';
import type { Cheerio } from '../src/cheerio.js';
import type { CheerioAPI } from '../src/load.js';
import { JSDOM } from 'jsdom';
import { load } from '../src/base-exports.js';
import { load } from '../src/load-parse.js';

const documentDir = new URL('documents/', import.meta.url);
const jQuerySrc = await fs.readFile(
Expand Down
6 changes: 6 additions & 0 deletions src/__fixtures__/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type { CheerioAPI } from '../load.js';
import { load } from '../load-parse.js';

/** A Cheerio instance with no content. */
export const cheerio: CheerioAPI = load([]);

export const fruits: string = [
'<ul id="fruits">',
'<li class="apple">Apple</li>',
Expand Down
9 changes: 4 additions & 5 deletions src/__tests__/deprecated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* maintained until that time.
*/
import { describe, it, expect, beforeEach } from 'vitest';
import * as fixtures from '../__fixtures__/fixtures.js';
import cheerio from '../index.js';
import { cheerio, food, fruits } from '../__fixtures__/fixtures.js';

describe('deprecated APIs', () => {
describe('cheerio module', () => {
Expand Down Expand Up @@ -95,7 +94,7 @@ describe('deprecated APIs', () => {
let $: typeof cheerio;

beforeEach(() => {
$ = cheerio.load(fixtures.food);
$ = cheerio.load(food);
});

it('(container, contained) : should correctly detect the provided element', () => {
Expand Down Expand Up @@ -131,7 +130,7 @@ describe('deprecated APIs', () => {

describe('Cheerio function', () => {
it('.load', () => {
const $1 = cheerio.load(fixtures.fruits);
const $1 = cheerio.load(fruits);
const $2 = $1.load('<div><p>Some <a>text</a>.</p></div>');

expect($2('a')).toHaveLength(1);
Expand Down Expand Up @@ -173,7 +172,7 @@ describe('deprecated APIs', () => {
});

it('(selector) : should return the outerHTML of the selected element', () => {
const $ = cheerio.load(fixtures.fruits);
const $ = cheerio.load(fruits);
expect($.html('.pear')).toBe('<li class="pear">Pear</li>');
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/api/attributes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it, expect, beforeEach } from 'vitest';
import cheerio, { load, type CheerioAPI, type Cheerio } from '../index.js';
import { load, type CheerioAPI, type Cheerio } from '../index.js';
import type { Element } from 'domhandler';
import {
cheerio,
script,
fruits,
vegetables,
Expand Down
4 changes: 2 additions & 2 deletions src/api/css.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest';
import cheerio, { load, type Cheerio } from '../index.js';
import { load, type Cheerio } from '../index.js';
import type { Element } from 'domhandler';
import { mixedText } from '../__fixtures__/fixtures.js';
import { cheerio, mixedText } from '../__fixtures__/fixtures.js';

describe('$(...)', () => {
describe('.css', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import * as fixtures from '../__fixtures__/fixtures.js';
import { load } from '../base-exports.js';
import { load } from '../load-parse.js';

interface RedSelObject {
red: string | undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/api/forms.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest';
import cheerio, { type CheerioAPI } from '../index.js';
import { forms } from '../__fixtures__/fixtures.js';
import { type CheerioAPI } from '../index.js';
import { cheerio, forms } from '../__fixtures__/fixtures.js';

describe('$(...)', () => {
let $: CheerioAPI;
Expand Down
45 changes: 23 additions & 22 deletions src/api/traversing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, it, expect, beforeEach } from 'vitest';
import cheerio, { type CheerioAPI } from '../index.js';
import { load, type CheerioAPI } from '../index.js';
import { Cheerio } from '../cheerio.js';
import { type AnyNode, type Element, type Text, isText } from 'domhandler';
import {
cheerio,
food,
fruits,
eleven,
Expand All @@ -23,13 +24,13 @@ describe('$(...)', () => {
let $: CheerioAPI;

beforeEach(() => {
$ = cheerio.load(fruits);
$ = load(fruits);
});

describe('.load', () => {
it('should throw a TypeError if given invalid input', () => {
expect(() => {
(cheerio.load as any)();
(load as any)();
}).toThrow('cheerio.load() expects a string');
});
});
Expand Down Expand Up @@ -77,20 +78,20 @@ describe('$(...)', () => {
});

it('should query immediate descendant only', () => {
const q = cheerio.load('<foo><bar><bar></bar><bar></bar></bar></foo>');
const q = load('<foo><bar><bar></bar><bar></bar></bar></foo>');
expect(q('foo').find('> bar')).toHaveLength(1);
});

it('should find siblings', () => {
const q = cheerio.load('<p class=a><p class=b></p>');
const q = load('<p class=a><p class=b></p>');
expect(q('.a').find('+.b')).toHaveLength(1);
expect(q('.a').find('~.b')).toHaveLength(1);
expect(q('.a').find('+.a')).toHaveLength(0);
expect(q('.a').find('~.a')).toHaveLength(0);
});

it('should query case-sensitively when in xml mode', () => {
const q = cheerio.load('<caseSenSitive allTheWay>', { xml: true });
const q = load('<caseSenSitive allTheWay>', { xml: true });
expect(q('caseSenSitive')).toHaveLength(1);
expect(q('[allTheWay]')).toHaveLength(1);
expect(q('casesensitive')).toHaveLength(0);
Expand All @@ -105,7 +106,7 @@ describe('$(...)', () => {

describe('(cheerio object) :', () => {
it('returns only those nodes contained within the current selection', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('#fruits').find(q('li'));

expect($selection).toHaveLength(3);
Expand All @@ -114,7 +115,7 @@ describe('$(...)', () => {
expect($selection[2]).toBe(q('.pear')[0]);
});
it('returns only those nodes contained within any element in the current selection', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('.apple, #vegetables').find(q('li'));

expect($selection).toHaveLength(2);
Expand All @@ -125,21 +126,21 @@ describe('$(...)', () => {

describe('(node) :', () => {
it('returns node when contained within the current selection', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('#fruits').find(q('.apple')[0]);

expect($selection).toHaveLength(1);
expect($selection[0]).toBe(q('.apple')[0]);
});
it('returns node when contained within any element the current selection', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('#fruits, #vegetables').find(q('.carrot')[0]);

expect($selection).toHaveLength(1);
expect($selection[0]).toBe(q('.carrot')[0]);
});
it('does not return node that is not contained within the current selection', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('#fruits').find(q('.carrot')[0]);

expect($selection).toHaveLength(0);
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('$(...)', () => {

describe('.contents', () => {
beforeEach(() => {
$ = cheerio.load(text);
$ = load(text);
});

it('() : should get all contents', () => {
Expand Down Expand Up @@ -219,7 +220,7 @@ describe('$(...)', () => {
});

it('() : should return elements in order', () => {
const result = cheerio.load(eleven)('.red').next();
const result = load(eleven)('.red').next();
expect(result).toHaveLength(2);
expect(result.eq(0).text()).toBe('Six');
expect(result.eq(1).text()).toBe('Ten');
Expand Down Expand Up @@ -384,7 +385,7 @@ describe('$(...)', () => {
});

it('() : should maintain elements order', () => {
const sel = cheerio.load(eleven)('.sel');
const sel = load(eleven)('.sel');
expect(sel).toHaveLength(3);
expect(sel.eq(0).text()).toBe('Three');
expect(sel.eq(1).text()).toBe('Nine');
Expand Down Expand Up @@ -566,7 +567,7 @@ describe('$(...)', () => {
});

it('() : when two elements are siblings to each other they have to be included', () => {
const result = cheerio.load(eleven)('.sel').siblings();
const result = load(eleven)('.sel').siblings();
expect(result).toHaveLength(7);
expect(result.eq(0).text()).toBe('One');
expect(result.eq(1).text()).toBe('Two');
Expand All @@ -578,14 +579,14 @@ describe('$(...)', () => {
});

it('(selector) : when two elements are siblings to each other they have to be included', () => {
const result = cheerio.load(eleven)('.sel').siblings('.red');
const result = load(eleven)('.sel').siblings('.red');
expect(result).toHaveLength(2);
expect(result.eq(0).text()).toBe('Four');
expect(result.eq(1).text()).toBe('Nine');
});

it('(cheerio) : test filtering with cheerio object', () => {
const doc = cheerio.load(eleven);
const doc = load(eleven);
const result = doc('.sel').siblings(doc(':not([class])'));
expect(result).toHaveLength(4);
expect(result.eq(0).text()).toBe('One');
Expand All @@ -597,7 +598,7 @@ describe('$(...)', () => {

describe('.parents', () => {
beforeEach(() => {
$ = cheerio.load(food);
$ = load(food);
});

it('() : should get all of the parents in logical order', () => {
Expand Down Expand Up @@ -648,7 +649,7 @@ describe('$(...)', () => {

describe('.parentsUntil', () => {
beforeEach(() => {
$ = cheerio.load(food);
$ = load(food);
});

it('() : should get all of the parents in logical order', () => {
Expand Down Expand Up @@ -1012,7 +1013,7 @@ describe('$(...)', () => {

describe('.has', () => {
beforeEach(() => {
$ = cheerio.load(food);
$ = load(food);
});

it('(selector) : should reduce the set of matched elements to those with descendants that match the selector', () => {
Expand Down Expand Up @@ -1278,7 +1279,7 @@ describe('$(...)', () => {
let $pear: Cheerio<Element>;

beforeEach(() => {
$ = cheerio.load(food);
$ = load(food);
$fruits = $('#fruits');
$apple = $('.apple');
$orange = $('.orange');
Expand Down Expand Up @@ -1579,7 +1580,7 @@ describe('$(...)', () => {
expect($selection[1]).toBe($('.apple')[0]);
});
it('includes parents and self', () => {
const q = cheerio.load(food);
const q = load(food);
const $selection = q('.apple').parents().addBack();

expect($selection).toHaveLength(5);
Expand Down
30 changes: 0 additions & 30 deletions src/base-exports.spec.ts

This file was deleted.

Loading

0 comments on commit d4eb8d3

Please sign in to comment.