Use groups for integration and unit tests

This commit is contained in:
Bill Thornton 2021-09-21 00:38:48 -04:00
parent 5b73fcd9d6
commit 9d52fae060
12 changed files with 49 additions and 15 deletions

View File

@ -68,7 +68,7 @@ jobs:
run: npm ci --no-audit
- name: Run jest
run: npx jest --coverage
run: npx jest --coverage --group=unit
- name: Upload coverage
uses: codecov/codecov-action@v2.1.0

View File

@ -1,5 +1,7 @@
.github
.vscode
__helpers__
__tests__
coverage

View File

@ -1,6 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
runner: 'groups',
testEnvironment: 'node',
collectCoverageFrom: [ 'src/**' ],
coveragePathIgnorePatterns: [ 'generated-client' ]

6
package-lock.json generated
View File

@ -4109,6 +4109,12 @@
}
}
},
"jest-runner-groups": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/jest-runner-groups/-/jest-runner-groups-2.1.0.tgz",
"integrity": "sha512-iHBIJ38yEW7qkPTW3tSulq/5kjgIiVtZjuYimBT1PltBYwsb1B1gPWGFMDdEfy9O3+6cyfe5MmVgMHafi69MUw==",
"dev": true
},
"jest-runtime": {
"version": "27.2.1",
"resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-27.2.1.tgz",

View File

@ -23,7 +23,7 @@
"fix-schema": "node scripts/modify-schema.mjs openapi.json",
"lint": "eslint \".\"",
"prepublishOnly": "npm run build:sdk",
"test": "jest --watchAll"
"test": "jest --watchAll --group=unit"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.4.4",
@ -37,6 +37,7 @@
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.2",
"jest": "^27.2.0",
"jest-runner-groups": "^2.1.0",
"ts-jest": "^27.0.5",
"typedoc": "^0.22.4",
"typedoc-plugin-markdown": "^3.11.0",

View File

@ -15,6 +15,11 @@ import { getAuthorizationHeader } from '../utils';
jest.mock('axios');
const mockAxios = mocked(axios, true);
/**
* Api class tests.
*
* @group unit
*/
describe('Api', () => {
it('should authenticate and update state', async () => {
const TEST_ACCESS_TOKEN = 'TEST-ACCESS-TOKEN';

View File

@ -8,6 +8,11 @@ import { Jellyfin } from '..';
import { TEST_CLIENT, TEST_DEVICE } from '../__helpers__/common';
import { Discovery } from '../discovery';
/**
* Discovery class tests.
*
* @group unit
*/
describe('Discovery', () => {
it('should return a list of candidates', () => {
const jellyfin = new Jellyfin({

View File

@ -5,22 +5,16 @@
*/
import { Jellyfin } from '..';
import { TEST_CLIENT, TEST_DEVICE } from '../__helpers__/common';
// FIXME: These tests should be mocked and not calling an actual server
const SERVER_URL = 'https://demo.jellyfin.org/stable';
const TEST_CLIENT = {
name: 'sdk-test-client',
version: '0.0.0'
};
const TEST_DEVICE = {
name: 'device-name',
id: 'device-id'
};
// Skipping because this is an integration test
describe.skip('Test the Base SDK', () => {
/**
* SDK integration tests.
*
* @group integration
*/
describe('Test the Base SDK', () => {
it('public users api', async () => {
const jellyfin = new Jellyfin({
clientInfo: TEST_CLIENT,

View File

@ -7,6 +7,11 @@
import { Api, Jellyfin } from '..';
import { TEST_CLIENT, TEST_DEVICE, SERVER_URL } from '../__helpers__/common';
/**
* Api Jellyfin tests.
*
* @group unit
*/
describe('Jellyfin', () => {
it('should create an api instance', () => {
const ACCESS_TOKEN = 'ACCESS TOKEN';

View File

@ -6,6 +6,11 @@
import { getAddressCandidates } from '..';
/**
* Address Candidates tests.
*
* @group unit/utils
*/
describe('Address Candidates', () => {
describe('getAddressCandidates()', () => {
it('should return candidates for a given domain', () => {

View File

@ -7,6 +7,11 @@
import { getAuthorizationHeader } from '..';
import { TEST_CLIENT, TEST_DEVICE } from '../../__helpers__/common';
/**
* Authentication tests.
*
* @group unit/utils
*/
describe('Authentication', () => {
it('should return the correct header value without token', () => {
const header = getAuthorizationHeader(TEST_CLIENT, TEST_DEVICE);

View File

@ -8,6 +8,11 @@ import Url from 'url-parse';
import { getDefaultPort, HTTP_PORT, HTTPS_PORT, HTTPS_PROTOCOL, HTTP_PROTOCOL, copyUrl, parseUrl } from '..';
/**
* Url tests.
*
* @group unit/utils
*/
describe('Url', () => {
describe('copyUrl()', () => {
it('should return a copy', () => {