Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -91,22 +91,22 @@ jobs:
os: windows-latest
shell: cmd
node-version:
- 18.17.0
- 18.x
- 20.5.0
- 20.17.0
- 20.x
- 22.9.0
- 22.x
- 24.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.5.0
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 24.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand Down Expand Up @@ -140,9 +140,11 @@ jobs:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
- name: Test (with coverage on Node >= 24)
if: ${{ startsWith(matrix.node-version, '24') }}
run: npm run test:cover --ignore-scripts
- name: Test (without coverage on Node < 24)
if: ${{ !startsWith(matrix.node-version, '24') }}
run: npm test --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -67,22 +67,22 @@ jobs:
os: windows-latest
shell: cmd
node-version:
- 18.17.0
- 18.x
- 20.5.0
- 20.17.0
- 20.x
- 22.9.0
- 22.x
- 24.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.5.0
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 24.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand All @@ -106,7 +106,9 @@ jobs:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
- name: Test (with coverage on Node >= 24)
if: ${{ startsWith(matrix.node-version, '24') }}
run: npm run test:cover --ignore-scripts
- name: Test (without coverage on Node < 24)
if: ${{ !startsWith(matrix.node-version, '24') }}
run: npm test --ignore-scripts
6 changes: 3 additions & 3 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand All @@ -54,7 +54,7 @@ jobs:
else
# strip leading slash from directory so it works as a
# a path to the workspace flag
echo "workspace=-w ${dependabot_dir#/}" >> $GITHUB_OUTPUT
echo "workspace=--workspace ${dependabot_dir#/}" >> $GITHUB_OUTPUT
fi

- name: Apply Changes
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -119,8 +119,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
22 changes: 9 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"author": "GitHub Inc.",
"main": "lib/index.js",
"scripts": {
"test": "tap",
"test": "node --test",
"lint": "npm run eslint",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run eslint -- --fix",
"snap": "tap",
"snap": "node --test --test-update-snapshots",
"posttest": "npm run lint",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100"
},
"repository": {
"type": "git",
Expand All @@ -21,25 +22,20 @@
"license": "ISC",
"devDependencies": {
"@npmcli/eslint-config": "^5.0.0",
"@npmcli/template-oss": "4.26.0",
"tap": "^16.3.0"
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
"@npmcli/template-oss": "4.26.0"
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^18.17.0 || >=20.5.0"
"node": "^20.17.0 || >=22.9.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.26.0",
"publish": true
"publish": true,
"testRunner": "node:test",
"latestCiVersion": 24
}
}
120 changes: 61 additions & 59 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
const t = require('node:test')
const a = require('node:assert')
const abbrev = require('../')
const t = require('tap')
const util = require('util')

function test (list, expect) {
let actual = abbrev(list)
t.same(actual, expect,
'abbrev(' + util.inspect(list) + ') === ' + util.inspect(expect) + '\n' +
'actual: ' + util.inspect(actual))
const suite = [
[
'test',
{ t: 'test', te: 'test', tes: 'test', test: 'test' },
], [
['ruby', 'ruby', 'rules', 'rules', 'rules'],
{ rub: 'ruby',
ruby: 'ruby',
rul: 'rules',
rule: 'rules',
rules: 'rules',
},
], [
['fool', 'foom', 'pool', { toString: () => 'pope' }],
{ fool: 'fool',
foom: 'foom',
poo: 'pool',
pool: 'pool',
pop: 'pope',
pope: 'pope',
},
], [
['a', 'ab', 'abc', 'abcd', 'abcde', 'acde'],
{ a: 'a',
ab: 'ab',
abc: 'abc',
abcd: 'abcd',
abcde: 'abcde',
ac: 'acde',
acd: 'acde',
acde: 'acde',
},
], [
['a', 'ab', 'abc', 'abcd', 'abcde', 'acde'].reverse(),
{ a: 'a',
ab: 'ab',
abc: 'abc',
abcd: 'abcd',
abcde: 'abcde',
ac: 'acde',
acd: 'acde',
acde: 'acde',
},
],
]

actual = abbrev(...list)
t.same(abbrev(...list), expect,
'abbrev(' + list.map(JSON.stringify).join(',') + ') === ' + util.inspect(expect) + '\n' +
'actual: ' + util.inspect(actual))
}

t.test('single string input', t => {
const result = abbrev('asdf')
t.same(result, {
a: 'asdf',
as: 'asdf',
asd: 'asdf',
asdf: 'asdf',
}, 'correctly abbreviates a single string')
t.end()
})
for (let i = 0; i < suite.length; i++) {
t.test(`test ${i}`, () => {
const [list, expect] = suite[i]
let actual = abbrev(list)
a.deepEqual(actual, expect,
'abbrev(' + util.inspect(list) + ') === ' + util.inspect(expect) + '\n' +
'actual: ' + util.inspect(actual))

test(['ruby', 'ruby', 'rules', 'rules', 'rules'],
{ rub: 'ruby',
ruby: 'ruby',
rul: 'rules',
rule: 'rules',
rules: 'rules',
})
test(['fool', 'foom', 'pool', { toString: () => 'pope' }],
{ fool: 'fool',
foom: 'foom',
poo: 'pool',
pool: 'pool',
pop: 'pope',
pope: 'pope',
})
test(['a', 'ab', 'abc', 'abcd', 'abcde', 'acde'],
{ a: 'a',
ab: 'ab',
abc: 'abc',
abcd: 'abcd',
abcde: 'abcde',
ac: 'acde',
acd: 'acde',
acde: 'acde',
if (Array.isArray(list)) {
actual = abbrev(...list)
a.deepEqual(abbrev(...list), expect,
'abbrev(' + list.map(JSON.stringify).join(',') + ') === ' + util.inspect(expect) + '\n' +
'actual: ' + util.inspect(actual))
}
})
test(['a', 'ab', 'abc', 'abcd', 'abcde', 'acde'].reverse(),
{ a: 'a',
ab: 'ab',
abc: 'abc',
abcd: 'abcd',
abcde: 'abcde',
ac: 'acde',
acd: 'acde',
acde: 'acde',
})

t.notOk([].abbrev)
t.notOk({}.abbrev)
}
Loading