Skip to content

Commit

Permalink
Merge pull request #3 from f3rno64/2-fix-color-tests-gh-actions
Browse files Browse the repository at this point in the history
Fix: Color func tests
  • Loading branch information
f3rno64 authored Jan 5, 2024
2 parents 4787991 + dd9bc7c commit cb5b173
Show file tree
Hide file tree
Showing 33 changed files with 236 additions and 113 deletions.
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
"browser": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "mocha"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:mocha/recommended"
],
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
Expand Down
50 changes: 50 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 @@ -56,6 +56,7 @@
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"eslint": "^8.55.0",
"eslint-plugin-mocha": "^10.2.0",
"husky": "^8.0.3",
"is-ansi": "^1.0.0",
"mocha": "^10.2.0",
Expand Down
22 changes: 18 additions & 4 deletions src/tests/color/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clDate } from '../../color'

describe('color:date', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:date', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clDate('2018-01-01'))).to.equal(true)
})

it('accepts numeric timestamps', () => {
it('accepts numeric timestamps', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clDate(Date.now()))).to.equal(true)
})

it('accepts date objects', () => {
it('accepts date objects', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clDate(new Date()))).to.equal(true)
})
})
16 changes: 13 additions & 3 deletions src/tests/color/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clDuration } from '../../color'

describe('color:duration', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:duration', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clDuration('10000'))).to.equal(true)
})

it('accepts numeric values', () => {
it('accepts numeric values', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clDuration(42))).to.equal(true)
})
})
16 changes: 13 additions & 3 deletions src/tests/color/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clError } from '../../color'

describe('color:error', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:error', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clError('Some error'))).to.equal(true)
})

it('accepts error objects', () => {
it('accepts error objects', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clError(new Error('Some error')))).to.equal(true)
})
})
10 changes: 8 additions & 2 deletions src/tests/color/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clHighlight } from '../../color'

describe('color:highlight', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:highlight', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clHighlight('Some text'))).to.equal(true)
})
})
10 changes: 8 additions & 2 deletions src/tests/color/highlight_red.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clHighlightRed } from '../../color'

describe('color:highlight_red', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:highlight_red', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clHighlightRed('Some text'))).to.equal(true)
})
})
16 changes: 13 additions & 3 deletions src/tests/color/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clID } from '../../color'

describe('color:id', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:id', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clID('id'))).to.equal(true)
})

it('accepts numeric values', () => {
it('accepts numeric values', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clID(42))).to.equal(true)
})
})
10 changes: 8 additions & 2 deletions src/tests/color/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clSheet } from '../../color'

describe('color:sheet', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:sheet', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clSheet('name'))).to.equal(true)
})
})
10 changes: 8 additions & 2 deletions src/tests/color/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import isAnsi from 'is-ansi'
import { expect } from 'chai'
import { clText } from '../../color'

describe('color:text', () => {
it('colors the provided string', () => {
const { CI } = process.env

describe('color:text', function () {
it('colors the provided string', function () {
if (CI) {
return this.skip()
}

expect(isAnsi(clText('some value'))).to.equal(true)
})
})
26 changes: 13 additions & 13 deletions src/tests/commands/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ const getArgs = (overrides?: Record<string, unknown>): EditCommandArgs => ({
...(overrides ?? {})
})

describe('commands:edit:handler', () => {
beforeEach(async () => {
describe('commands:edit:handler', function () {
beforeEach(async function () {
await db.load()
})

afterEach(async () => {
afterEach(async function () {
await db.delete()
})

it('throws an error if no sheet or entry is specified', async () => {
it('throws an error if no sheet or entry is specified', async function () {
const p = handler(getArgs())

chai.expect(p).to.be.rejectedWith('No sheet or entry specified')
})

it('throws an error if the specified sheet does not exist', () => {
it('throws an error if the specified sheet does not exist', function () {
const sheetA = DB.genSheet('test-sheet-a')
const sheetB = DB.genSheet('test-sheet-b')

Expand All @@ -46,7 +46,7 @@ describe('commands:edit:handler', () => {
chai.expect(p).to.be.rejectedWith('Sheet test-sheet-c not found')
})

it('throws an error if the specified sheet entry does not exist', () => {
it('throws an error if the specified sheet entry does not exist', function () {
const entryA = DB.genSheetEntry(0, 'test-entry-a')
const entryB = DB.genSheetEntry(1, 'test-entry-b')
const sheet = DB.genSheet('test-sheet', [entryA, entryB])
Expand All @@ -58,7 +58,7 @@ describe('commands:edit:handler', () => {
chai.expect(p).to.be.rejectedWith('Entry 42 not found in sheet test-sheet')
})

it('throws an error if editing a sheet but no name was provided', () => {
it('throws an error if editing a sheet but no name was provided', function () {
const sheetA = DB.genSheet('test-sheet-a')
const sheetB = DB.genSheet('test-sheet-b')

Expand All @@ -70,7 +70,7 @@ describe('commands:edit:handler', () => {
chai.expect(p).to.be.rejectedWith('No new name specified')
})

it('edits the name of the specified sheet', async () => {
it('edits the name of the specified sheet', async function () {
const sheet = DB.genSheet('test-sheet-a')

db.db?.sheets.push(sheet)
Expand All @@ -80,7 +80,7 @@ describe('commands:edit:handler', () => {
expect(sheet.name).to.equal('new-name')
})

it('edits the description of the specified sheet entry', async () => {
it('edits the description of the specified sheet entry', async function () {
const entry = DB.genSheetEntry(0, 'test-description')
const sheet = DB.genSheet('test-sheet-a', [entry])

Expand All @@ -98,7 +98,7 @@ describe('commands:edit:handler', () => {
expect(sheet.entries[0].description).to.equal('new-description')
})

it('edits the start date of the specified sheet entry', async () => {
it('edits the start date of the specified sheet entry', async function () {
const startDate = new Date(Date.now() - 24 * 60 * 60 * 1000)
const newStartDate = new Date()
const entry = DB.genSheetEntry(0, 'test-description', startDate)
Expand All @@ -117,7 +117,7 @@ describe('commands:edit:handler', () => {
expect(+entry.start).to.equal(+newStartDate)
})

it('edits the end date of the specified sheet entry', async () => {
it('edits the end date of the specified sheet entry', async function () {
const startDate = new Date(Date.now() - 48 * 60 * 60 * 1000)
const endDate = new Date(Date.now() - 24 * 60 * 60 * 1000)
const newEndDate = new Date()
Expand All @@ -137,7 +137,7 @@ describe('commands:edit:handler', () => {
expect(+(entry.end === null ? 0 : entry.end)).to.equal(+newEndDate)
})

it('deletes the specified sheet if requested', async () => {
it('deletes the specified sheet if requested', async function () {
const sheetA = DB.genSheet('test-sheet-a')
const sheetB = DB.genSheet('test-sheet-b')

Expand All @@ -150,7 +150,7 @@ describe('commands:edit:handler', () => {
.undefined
})

it('deletes the specified sheet entry if requested', async () => {
it('deletes the specified sheet entry if requested', async function () {
const entryA = DB.genSheetEntry(0, 'test-entry-a')
const entryB = DB.genSheetEntry(1, 'test-entry-b')
const sheet = DB.genSheet('test-sheet-a', [entryA, entryB])
Expand Down
Loading

0 comments on commit cb5b173

Please sign in to comment.