Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Try running vitest instead of jest for co2.js #235

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@ name: Unit tests
on:
push:
branches:
- main
- ca-v0.10.0
- main
pull_request:
branches:
- main
- ca-v0.10.0
- main
permissions:
contents: read
contents: read
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Verify lint
run: npm run lint
- name: Run unit tests
run: npm test
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Verify lint
run: npm run lint
- name: Run unit tests
run: npm test
14 changes: 8 additions & 6 deletions __mocks__/https.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { vi } from "vitest";
import { getApiRequestHeaders } from "../src/helpers/index.js";
const https = jest.createMockFromModule("https");
import { Stream } from "stream";

const https = vi.mock("https");

const stream = new Stream();

https.get.mockImplementation((url, options, callback) => {
Expand All @@ -10,19 +12,19 @@ https.get.mockImplementation((url, options, callback) => {
stream.emit(
"data",
Buffer.from(
`{"google.com": {"url":"google.com","hosted_by":"Google Inc.","hosted_by_website":"https://www.google.com","partner":null,"green":true}, "pchome.com": {"url":"pchome.com","green":false} }`
)
`{"google.com": {"url":"google.com","hosted_by":"Google Inc.","hosted_by_website":"https://www.google.com","partner":null,"green":true}, "pchome.com": {"url":"pchome.com","green":false} }`,
),
);
} else {
stream.emit(
"data",
Buffer.from(
`{"url":"google.com","hosted_by":"Google Inc.","hosted_by_website":"https://www.google.com","partner":null,"green":true}`
)
`{"url":"google.com","hosted_by":"Google Inc.","hosted_by_website":"https://www.google.com","partner":null,"green":true}`,
),
);
}

stream.emit("end");
});

module.exports = https;
export default https;
Loading