Skip to content

Commit

Permalink
Merge pull request #85 from wopehq/update-tests-and-action-for-bun
Browse files Browse the repository at this point in the history
chore: update tests and action for bun
  • Loading branch information
irensaltali authored Mar 28, 2024
2 parents 737b2e7 + dedd3c6 commit 559f68f
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 961 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn test
env:
CI: true
bun-version: latest

- name: Install dependencies
run: bun install

- name: Run tests
run: bun test

- name: Build
run: bun run build
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"main": "build/index.js",
"scripts": {
"build": "tsc",
"coverage": "vitest --coverage",
"test": "vitest run",
"test": "bun test",
"lint": "eslint . --ext .ts",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write"
},
Expand All @@ -28,16 +27,15 @@
"cheerio": "^1.0.0-rc.12"
},
"devDependencies": {
"@types/bun": "^1.0.8",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitest/coverage-v8": "^1.3.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"prettier": "^3.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vitest": "^1.1.0"
"typescript": "^5.3.3"
}
}
14 changes: 7 additions & 7 deletions tests/execRegex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import execRegex from '../src/parser/regex/execRegex';

describe('execRegex Tests', () => {
it('Case 1: Pre-defined Regex - url', () => {
const value = 'test https://google.com/ ';
const result = execRegex(value, 'url');
expect('https://google.com/').to.deep.equal(result);
expect('https://google.com/').toEqual(result);
});

it('Case 1.1: Pre-defined Regex - url', () => {
const value = 'test https://google.com/images test ';
const result = execRegex(value, 'url');
expect('https://google.com/images').to.deep.equal(result);
expect('https://google.com/images').toEqual(result);
});

it('Case 1.2: Pre-defined Regex - url', () => {
const value = 'test https://google.com/images?q=sunset test ';
const result = execRegex(value, 'url');
expect('https://google.com/images?q=sunset').to.deep.equal(result);
expect('https://google.com/images?q=sunset').toEqual(result);
});

it('Case 2: Pre-defined Regex - email', () => {
const value = 'test test@email.com ';
const result = execRegex(value, 'email');
expect('test@email.com').to.deep.equal(result);
expect('test@email.com').toEqual(result);
});

it('Case 3: As Object', () => {
const value = 'test 26';
const result = execRegex(value, { pattern: '\\d+' });
expect('26').to.deep.equal(result);
expect('26').toEqual(result);
});

it('Case 4: As Regex Object ', () => {
const value = 'test 26';
const result = execRegex(value, /\d+/);
expect('26').to.deep.equal(result);
expect('26').toEqual(result);
});
});
8 changes: 4 additions & 4 deletions tests/getArrayValue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { load } from 'cheerio';
import getArrayValue from '../src/parser/getArrayValue';

Expand All @@ -23,7 +23,7 @@ describe('getArrayValue', () => {
'Third Child'
];

expect(result).to.be.deep.eq(expected);
expect(result).toEqual(expected);
});

it('withIgnoreChildren', () => {
Expand All @@ -33,7 +33,7 @@ describe('getArrayValue', () => {
);
const expected = ['First Child Second Child', 'Third Child'];

expect(result).to.be.deep.eq(expected);
expect(result).toEqual(expected);
});

it('withIgnoreParents', () => {
Expand All @@ -43,6 +43,6 @@ describe('getArrayValue', () => {
);
const expected = ['Second Child', 'Third Child'];

expect(result).to.be.deep.eq(expected);
expect(result).toEqual(expected);
});
});
26 changes: 13 additions & 13 deletions tests/getConfig.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';

import getConfig from '../src/config/getConfig';
import { type RawConfig } from '../src/config/types';
Expand All @@ -9,37 +9,37 @@ describe('getConfig Tests', () => {
const value = getConfig({}, config);
const expected = { selector: '', attr: 'href' };

expect(value).to.deep.equal(expected);
expect(value).toEqual(expected);
});

it('should return the same selector when given a string config without "@ attr"', () => {
const config: RawConfig = { selector: 'a.link' };
const value = getConfig({}, config);
expect({ selector: 'a.link' }).to.deep.equal(value);
expect({ selector: 'a.link' }).toEqual(value);
});

it('should return the selector and "href" attribute when given a string config with "selector @ attr"', () => {
const config: RawConfig = { selector: 'a.link @ href' };
const value = getConfig({}, config);
expect({ selector: 'a.link', attr: 'href' }).to.deep.equal(value);
expect({ selector: 'a.link', attr: 'href' }).toEqual(value);
});

it('should return the same selector when given an array config with multiple selectors', () => {
const config: RawConfig = { selector: 'a.link, b.link' };
const value = getConfig({}, config);
expect({ selector: 'a.link, b.link' }).to.deep.equal(value);
expect({ selector: 'a.link, b.link' }).toEqual(value);
});

it('should return the selector and attribute when given an object config with "selector" and "attr"', () => {
const config: RawConfig = { selector: 'a.link', attr: 'href' };
const value = getConfig({}, config);
expect({ selector: 'a.link', attr: 'href' }).to.deep.equal(value);
expect({ selector: 'a.link', attr: 'href' }).toEqual(value);
});

it('should return the selector and attribute when given an object config with "selector @ attr"', () => {
const config: RawConfig = { selector: 'a.link @ href' };
const value = getConfig({}, config);
expect({ selector: 'a.link', attr: 'href' }).to.deep.equal(value);
expect({ selector: 'a.link', attr: 'href' }).toEqual(value);
});

it('should return the selector, attribute, and methods when given an object config with "selector @ attr | method"', () => {
Expand All @@ -49,7 +49,7 @@ describe('getConfig Tests', () => {
selector: 'a.link',
attr: 'href',
methods: ['url']
}).to.deep.equal(value);
}).toEqual(value);
});

it('should return the selector, attribute, and type when given an object config with "selector @ attr | array"', () => {
Expand All @@ -59,7 +59,7 @@ describe('getConfig Tests', () => {
selector: 'a.link',
attr: 'href',
type: 'array'
}).to.deep.equal(value);
}).toEqual(value);
});

it('should return the selector, attribute, and html flag when given an object config with "selector @ attr | html"', () => {
Expand All @@ -69,7 +69,7 @@ describe('getConfig Tests', () => {
selector: 'a.link',
attr: 'href',
html: true
}).to.deep.equal(value);
}).toEqual(value);
});

it('should return the selector, attribute, and html flag when given an object config as a function', () => {
Expand All @@ -83,7 +83,7 @@ describe('getConfig Tests', () => {
html: true
};

expect(value).to.deep.equal(expected);
expect(value).toEqual(expected);
});

it('should return the selector and exist flag when given an object config as a function', () => {
Expand All @@ -92,13 +92,13 @@ describe('getConfig Tests', () => {
expect({
selector: 'a.link',
exist: true
}).to.deep.equal(value);
}).toEqual(value);
});

it('should return the parsed selectors when given an array of string selectors', () => {
const selectors = ['a.link', 'b.link'];
const result = getConfig({}, selectors);
const expected = [{ selector: 'a.link' }, { selector: 'b.link' }];
expect(result).to.deep.equal(expected);
expect(result).toEqual(expected);
});
});
10 changes: 5 additions & 5 deletions tests/getElement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { load } from 'cheerio';
import { Config } from '../src/config/types';
import getElement from '../src/parser/getElement';
Expand Down Expand Up @@ -32,21 +32,21 @@ describe('getElement Tests', () => {
it('Case 1: { selector } without `element`', () => {
const config: Config = { selector: '.first-child' };
const element = getElement({ $ }, config);
expect('first-child').to.deep.equal(element.attr('class'));
expect('first-child').toEqual(element.attr('class') as string);
});

it('Case 2: { selector }', () => {
const el = '.blocks';
const config: Config = { selector: '.first-child' };
const element = getElement({ $, el }, config);
expect('first-child').to.deep.equal(element.attr('class'));
expect(1).to.deep.equal(element.length);
expect('first-child').toEqual(element.attr('class') as string);
expect(1).toEqual(element.length);
});

it('Case 3: { selector type: array }', () => {
const el = $('.parent').first();
const config: Config = { selector: 'div', type: 'array' };
const element = getElement({ $, el }, config);
expect(8).to.deep.equal(element.length);
expect(8).toEqual(element.length);
});
});
2 changes: 1 addition & 1 deletion tests/getSchemaValue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { Cheerio, Element, load } from 'cheerio';
import { Schema } from '../src/config/types';
import getSchemaValue from '../src/parser/getSchemaValue';
Expand Down
4 changes: 2 additions & 2 deletions tests/getSimpleValue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect } from 'bun:test';
import { load } from 'cheerio';
import getSimpleValue from '../src/parser/getSimpleValue';

Expand All @@ -16,6 +16,6 @@ describe('getSimpleValue', () => {
};
const value = getSimpleValue({ $, el }, config);

expect(value).to.eq(null);
expect(value).toEqual(null);
});
});
Loading

0 comments on commit 559f68f

Please sign in to comment.