From 65231c23f81df264e073cd824b403e67c7589905 Mon Sep 17 00:00:00 2001 From: Quinn Turner Date: Tue, 13 Dec 2022 09:49:30 -0400 Subject: [PATCH] Add failing test case for missing setters --- .eslintrc.json | 12 +++++-- .vscode/launch.json | 16 ++++++++++ jest-preset.cjs | 9 ++---- jest-puppeteer.config.cjs | 22 ++++++------- tests/Nodejs/14_Getters_Setters.test.ts | 42 +++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 tests/Nodejs/14_Getters_Setters.test.ts diff --git a/.eslintrc.json b/.eslintrc.json index 15472806..6261574b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,6 @@ "es2021": true }, "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], - "overrides": [], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": "latest", @@ -16,5 +15,14 @@ "linebreak-style": ["error", "unix"], "quotes": ["error", "double"], "semi": ["error", "always"] - } + }, + "overrides": [ + { + "files": ["*.cjs"], + "rules": { + "no-undef": "off", + "@typescript-eslint/no-var-requires": "off" + } + } + ] } diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..351645dc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest: current file", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["${fileBasenameNoExtension}"], + "console": "integratedTerminal", + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + } + } + ] + } diff --git a/jest-preset.cjs b/jest-preset.cjs index 83cdc796..e6e7d0ac 100644 --- a/jest-preset.cjs +++ b/jest-preset.cjs @@ -1,7 +1,4 @@ -const ts_preset = require('ts-jest/presets/default-esm/jest-preset.js'); -const puppeteer_preset = require('jest-puppeteer/jest-preset.js'); +const ts_preset = require("ts-jest/presets/default-esm/jest-preset.js"); +const puppeteer_preset = require("jest-puppeteer/jest-preset.js"); -module.exports = Object.assign( - ts_preset, - puppeteer_preset -); +module.exports = Object.assign(ts_preset, puppeteer_preset); diff --git a/jest-puppeteer.config.cjs b/jest-puppeteer.config.cjs index ac01979a..838d3597 100644 --- a/jest-puppeteer.config.cjs +++ b/jest-puppeteer.config.cjs @@ -1,12 +1,12 @@ module.exports = { - launch: { - dumpio: true, - headless: process.env.HEADLESS !== 'false', - }, - server: { - command: 'npm run test-puppeteer-serve', - port: 4444, - launchTimeout: 10000, - debug: true, - }, -} + launch: { + dumpio: true, + headless: process.env.HEADLESS !== "false", + }, + server: { + command: "npm run test-puppeteer-serve", + port: 4444, + launchTimeout: 10000, + debug: true, + }, +}; diff --git a/tests/Nodejs/14_Getters_Setters.test.ts b/tests/Nodejs/14_Getters_Setters.test.ts new file mode 100644 index 00000000..b3e03b9a --- /dev/null +++ b/tests/Nodejs/14_Getters_Setters.test.ts @@ -0,0 +1,42 @@ +import { ok } from "assert"; +import "ts-jest"; +import { Logger } from "../../src/index.js"; +import { mockConsoleLog } from "./helper.js"; + +class MissingSetter { + get test(): string { + return "test"; + } +} + +const missingSetter = { + get test(): string { + return "test"; + } +} + +describe("Getters and setters", () => { + beforeEach(() => { + mockConsoleLog(true, false); + }); + test("[class] should not print getters", (): void => { + const logger = new Logger({ + type: "hidden", + }); + const missingSetterObj = new MissingSetter(); + + const result = logger.info(missingSetterObj); + + ok(result); + Object.keys(result).forEach((key) => { + expect(key).not.toBe("test"); + }); + }); + test("[object] should print getters", (): void => { + const logger = new Logger({ + type: "hidden", + }); + const result = logger.info(missingSetter); + expect(result).toContain("test"); + }); +});