Skip to content

Commit

Permalink
Refactor spec to use built in node test runner and assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Jul 3, 2023
1 parent 38a8924 commit 20cc9e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"types": "index.d.ts",
"scripts": {
"test": "npm run verify && npm run spec",
"spec": "jasmine tests/spec.js",
"spec": "node --test --test-reporter spec spec.js",
"lint": "eslint .",
"format": "prettier --write '**/*.{js,json,yml}'",
"verify": "npm run lint && npm run format",
Expand Down
20 changes: 11 additions & 9 deletions tests/spec.js → spec.js
@@ -1,35 +1,37 @@
const subject = require('..')
const { describe, it } = require('node:test')
const assert = require('node:assert')
const subject = require('./')

describe('get-package-name', () => {
it('ignores non-string values', () => {
const tests = [undefined, null, false]

tests.forEach((test) => {
expect(subject(test)).toBeUndefined()
assert.equal(subject(test), undefined)
})
})

it('ignores non-package paths', () => {
const tests = ['/absolute/path/to/file.js', './relative/path/to/file.js']

tests.forEach((test) => {
expect(subject(test)).toBeUndefined()
assert.equal(subject(test), undefined)
})
})

it('ignores partial scoped paths', () => {
const tests = ['/path/to/node_modules/@scope', '/path/to/node_modules/@scope/']

tests.forEach((test) => {
expect(subject(test)).toBeUndefined()
assert.equal(subject(test), undefined)
})
})

it('does not throw error when given path ends with package folder', () => {
const tests = ['node_modules', '/node_modules', '/path/to/node_modules']

tests.forEach((test) => {
expect(subject(test)).toBeUndefined()
assert.equal(subject(test), undefined)
})
})

Expand All @@ -40,7 +42,7 @@ describe('get-package-name', () => {
]

tests.forEach((test) => {
expect(subject(test)).toBe('package-name')
assert.equal(subject(test), 'package-name')
})
})

Expand All @@ -51,7 +53,7 @@ describe('get-package-name', () => {
]

tests.forEach((test) => {
expect(subject(test)).toBe('package-name')
assert.equal(subject(test), 'package-name')
})
})

Expand All @@ -62,7 +64,7 @@ describe('get-package-name', () => {
]

tests.forEach((test) => {
expect(subject(test)).toBe('@namespace/package-name')
assert.equal(subject(test), '@namespace/package-name')
})
})

Expand All @@ -73,7 +75,7 @@ describe('get-package-name', () => {
]

tests.forEach((test) => {
expect(subject(test, 'bower_components')).toBe('package-name')
assert.equal(subject(test, 'bower_components'), 'package-name')
})
})
})

0 comments on commit 20cc9e1

Please sign in to comment.