Skip to content

Commit

Permalink
refactor: Add unit tests and in-code documentation to improve maintan…
Browse files Browse the repository at this point in the history
…ability
  • Loading branch information
mountaindude committed Dec 15, 2024
1 parent d59a010 commit 1e16135
Show file tree
Hide file tree
Showing 32 changed files with 383 additions and 50 deletions.
20 changes: 15 additions & 5 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const dotenv = require('dotenv');
dotenv.config({ path: './.test.env' });

/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
Expand All @@ -18,19 +21,18 @@ const config = {
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: true,
collectCoverage: false,
collectCoverage: true,
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// collectCoverageFrom: ['./src/**/*.{js,jsx}'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: ['/node_modules/', '/build/', '/dist/'],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
Expand All @@ -45,6 +47,14 @@ const config = {

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// coverageThreshold: {
// global: {
// branches: 90,
// functions: 90,
// lines: 90,
// statements: 90,
// },
// },

// A path to a custom dependency extractor
// dependencyExtractor: undefined,
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@babel/plugin-syntax-import-assertions": "^7.26.0",
"@eslint/js": "^9.15.0",
"@jest/globals": "^29.7.0",
"dotenv": "^16.4.7",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { createUserActivityBucketsCustomProperty } from '../lib/cmd/qseow/createuseractivitycp.js';
import { createUserActivityBucketsCustomProperty } from '../../lib/cmd/qseow/createuseractivitycp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getApps, getAppById } from '../lib/util/qseow/app.js';
import { getApps, getAppById } from '../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getApps, getAppById, appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { sleep } from '../globals.js';
import { getApps, getAppById, appExistById, deleteAppById } from '../../lib/util/qseow/app.js';
import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js';
import { sleep } from '../../globals.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';
import { validate as uuidValidate } from 'uuid';

import { scrambleField } from '../lib/cmd/qseow/scramblefield.js';
import { scrambleField } from '../../lib/cmd/qseow/scramblefield.js';

let options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { testConnection } from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { testConnection } from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getScript } from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getScript } from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { taskExistById, getTaskByName, getTaskById } from '../lib/util/qseow/task.js';
import { taskExistById, getTaskByName, getTaskById } from '../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';

import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';
import { setTaskCustomProperty } from '../../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';

import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';
import { setTaskCustomProperty } from '../../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { getTask } from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { getTask } from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { jest, test, expect, describe } from '@jest/globals';

import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';
import { importTaskFromFile } from '../../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../lib/util/qseow/task.js';
import { mapTaskType } from '../../lib/util/qseow/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { jest, test, expect, describe } from '@jest/globals';

import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';
import { importTaskFromFile } from '../../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../lib/util/qseow/task.js';
import { mapTaskType } from '../../lib/util/qseow/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { taskExistById, getTaskByName, getTaskById } from '../lib/util/qseow/task.js';
import { taskExistById, getTaskByName, getTaskById } from '../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/testdata/test-file-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
1 change: 1 addition & 0 deletions src/__tests__/testdata/unreadable-file-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
Loading

0 comments on commit 1e16135

Please sign in to comment.