Skip to content

Commit fb7ef5e

Browse files
authored
Merge pull request #18 from remotemerge/update-code
Update code
2 parents 3722cb7 + 1003277 commit fb7ef5e

21 files changed

+2525
-11043
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/.idea/
33
/__tests__/
44
/dist/
5-
/public/
5+
/node_modules/

.github/workflows/install.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ on:
1010

1111
jobs:
1212
install:
13-
# OS to run
14-
runs-on: ubuntu-latest
13+
# The matrix of OS and Node.js versions
14+
strategy:
15+
matrix:
16+
os: [ ubuntu-latest, macos-latest, windows-latest ]
17+
node: [ 14, 16, 18, 'current' ]
1518

16-
steps:
17-
# checkout the code
18-
- uses: actions/checkout@v3
19+
# The type of runner that the job will run on
20+
runs-on: ${{ matrix.os }}
1921

20-
# Use nodejs LTS version
21-
- uses: actions/setup-node@v3
22+
steps:
23+
- name: "Use specified Node.js version"
24+
uses: actions/setup-node@v3
2225
with:
23-
node-version: 'lts/*'
26+
node-version: ${{ matrix.node }}
2427

2528
- name: "Print version"
2629
run: node -v && npm -v
2730

28-
- name: "Clean the directory"
29-
run: rm -rf *
30-
3131
- name: "Init package config"
3232
run: npm init -y
3333

.github/workflows/production.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ on:
99

1010
jobs:
1111
publish:
12-
# OS to run
12+
# The type of runner that the job will run on
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- name: "Checkout repository"
17+
uses: actions/checkout@v3
1718

1819
- name: "Install dependencies and build"
1920
run: npm install && npm run build
2021

21-
- name: "Copy readme doc"
22-
run: \cp README.md ./dist/README.md
23-
2422
# publish to NPM
2523
- uses: actions/setup-node@v3
2624
with:

.github/workflows/testing.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ on: [pull_request]
66

77
jobs:
88
test:
9-
# OS to run
10-
runs-on: ubuntu-latest
9+
# The matrix of OS and Node.js versions
10+
strategy:
11+
matrix:
12+
os: [ ubuntu-latest, macos-latest, windows-latest ]
13+
14+
# The type of runner that the job will run on
15+
runs-on: ${{ matrix.os }}
1116

1217
steps:
13-
# checkout the code
14-
- uses: actions/checkout@v3
18+
- name: "Checkout repository"
19+
uses: actions/checkout@v3
1520

1621
# Use nodejs LTS version
1722
- uses: actions/setup-node@v3
1823
with:
1924
node-version: 'lts/*'
2025

21-
- name: "Print version"
22-
run: node -v && npm -v
23-
2426
- name: "Install dependencies and build"
2527
run: npm install && npm run build
2628

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Madan Sapkota
3+
Copyright (c) 2023 Madan Sapkota
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# <img src="./assets/logo.png" width="28" height="28"> XPath Parser
22

33
[![Package](https://img.shields.io/npm/v/@remotemerge/xpath-parser?logo=npm)](https://www.npmjs.com/package/@remotemerge/xpath-parser)
4-
![Build](https://img.shields.io/github/workflow/status/remotemerge/xpath-parser/Production?logo=github)
4+
![Build](https://img.shields.io/github/actions/workflow/status/remotemerge/xpath-parser/production.yml?logo=github)
55
![Downloads](https://img.shields.io/npm/dt/@remotemerge/xpath-parser)
66
![License](https://img.shields.io/npm/l/@remotemerge/xpath-parser)
77

__tests__/multi-query.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import XpathParser from '../dist/xpath-parser.js';
1+
import { test } from 'vitest';
2+
import assert from 'assert';
3+
4+
import Parser from '../dist/index.es.js';
25
import htmlContent from './data/product.html';
36

4-
const parser = new XpathParser(htmlContent);
7+
const parser = new Parser(htmlContent);
58
const product = parser.multiQuery({
69
title: '//div[@id="ppd"]//span[@id="productTitle"]',
710
seller: '//div[@id="ppd"]//a[@id="bylineInfo"]',
@@ -10,23 +13,24 @@ const product = parser.multiQuery({
1013
});
1114

1215
test('must return an object', () => {
13-
expect(typeof product).toBe('object');
16+
assert.strictEqual(typeof product, 'object');
1417
});
1518

1619
test('must have four elements', () => {
17-
expect(Object.keys(product).length).toBe(4);
20+
assert.strictEqual(Object.keys(product).length, 4);
1821
});
1922

2023
test('match the product title', () => {
21-
expect(product.title).toBe(
24+
assert.strictEqual(
25+
product.title,
2226
'LETSCOM Fitness Tracker HR, Activity Tracker Watch with Heart Rate Monitor, Waterproof Smart Fitness Band with Step Counter, Calorie Counter, Pedometer Watch for Kids Women and Men',
2327
);
2428
});
2529

2630
test('product price contains dollar sign', () => {
27-
expect(product.price).toMatch('$');
31+
assert(product.price.includes('$'));
2832
});
2933

3034
test('product rating contains numbers', () => {
31-
expect(product.rating).toMatch(/\d+/);
35+
assert(product.rating.match(/\d+/));
3236
});

__tests__/query-first.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import XpathParser from '../dist/xpath-parser.js';
1+
import { test } from 'vitest';
2+
import assert from 'assert';
3+
4+
import Parser from '../dist/index.es.js';
25
import htmlContent from './data/product.html';
36

4-
const parser = new XpathParser(htmlContent);
7+
const parser = new Parser(htmlContent);
58
const str = parser.queryFirst('//span[@id="productTitle"]');
69

710
test('title must be string', () => {
8-
expect(typeof str).toBe('string');
11+
assert.strictEqual(typeof str, 'string');
912
});
1013

1114
test('match the title', () => {
12-
expect(str).toBe(
15+
assert.strictEqual(
16+
str,
1317
'LETSCOM Fitness Tracker HR, Activity Tracker Watch with Heart Rate Monitor, Waterproof Smart Fitness Band with Step Counter, Calorie Counter, Pedometer Watch for Kids Women and Men',
1418
);
1519
});

__tests__/query-list.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import XpathParser from '../dist/xpath-parser.js';
1+
import { test } from 'vitest';
2+
import assert from 'assert';
3+
4+
import Parser from '../dist/index.es.js';
25
import htmlContent from './data/products.html';
36

4-
const parser = new XpathParser(htmlContent);
7+
const parser = new Parser(htmlContent);
58
const results = parser.queryList('//span[contains(@class, "zg-item")]/a/div');
69

710
test('must return object', () => {
8-
expect(typeof results).toBe('object');
11+
assert.strictEqual(typeof results, 'object');
912
});
1013

1114
test('must have 50 titles', () => {
12-
expect(results.length).toBe(50);
15+
assert.strictEqual(results.length, 50);
1316
});
1417

15-
test('match the fist title', () => {
16-
expect(results[0]).toBe('Cell Phone Stand,Angle Height Adjustable Stable LISEN Cell Phone Stand For Desk,Sturdy…');
18+
test('match the first title', () => {
19+
assert.strictEqual(
20+
results[0],
21+
'Cell Phone Stand,Angle Height Adjustable Stable LISEN Cell Phone Stand For Desk,Sturdy…',
22+
);
1723
});

__tests__/sub-query.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import XpathParser from '../dist/xpath-parser.js';
1+
import { test } from 'vitest';
2+
import assert from 'assert';
3+
4+
import Parser from '../dist/index.es.js';
25
import htmlContent from './data/products.html';
36

4-
const parser = new XpathParser(htmlContent);
7+
const parser = new Parser(htmlContent);
58
const products = parser.subQuery({
69
root: '//span[contains(@class, "zg-item")]',
710
pagination: '//ul/li/a[contains(text(), "Next")]/@href',
@@ -14,44 +17,41 @@ const products = parser.subQuery({
1417
});
1518

1619
test('must return an object', () => {
17-
expect(typeof products).toBe('object');
20+
assert.strictEqual(typeof products, 'object');
1821
});
1922

20-
test('must have one or two elements', () => {
21-
expect(Object.keys(products).length).toBeGreaterThanOrEqual(1);
22-
expect(Object.keys(products).length).toBeLessThanOrEqual(2);
23+
test('must have resuts array and pagination url', () => {
24+
assert(Array.isArray(products.results));
25+
assert.strictEqual(typeof products.paginationUrl, 'string');
2326
});
2427

2528
test('pagination url is string', () => {
2629
if (products.paginationUrl) {
27-
expect(products).toMatchObject({
28-
paginationUrl: expect.any(String),
29-
});
30+
assert.strictEqual(typeof products.paginationUrl, 'string');
3031
}
3132
});
3233

3334
test('must have results array', () => {
34-
expect(products).toMatchObject({
35-
results: expect.any(Array),
36-
});
35+
assert(Array.isArray(products.results));
3736
});
3837

3938
test('each product must be an object', () => {
40-
expect(typeof products.results[0]).toBe('object');
39+
assert.strictEqual(typeof products.results[0], 'object');
4140
});
4241

4342
const firstProduct = products.results[0];
4443

4544
test('match the product title', () => {
46-
expect(firstProduct.title).toBe(
45+
assert.strictEqual(
46+
firstProduct.title,
4747
'Cell Phone Stand,Angle Height Adjustable Stable LISEN Cell Phone Stand For Desk,Sturdy Aluminum Metal Phone Holder,Compatible with Mobile Phone/iPad/Kindle/Tablet,4-10inch',
4848
);
4949
});
5050

5151
test('product price contains dollar sign', () => {
52-
expect(firstProduct.price).toMatch('$');
52+
assert(firstProduct.price.includes('$'));
5353
});
5454

5555
test('product image url starts with https', () => {
56-
expect(firstProduct.image).toMatch(/^https:\/\//);
56+
assert(firstProduct.image.startsWith('https://'));
5757
});

0 commit comments

Comments
 (0)