Skip to content

Commit

Permalink
Use node:assert to assert the registered compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Aug 15, 2023
1 parent 7692c37 commit f7f6527
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'node:assert/strict'
import { resolve } from 'node:path'
import { MessageChannel, receiveMessageOnPort, Worker } from 'node:worker_threads'

Expand All @@ -14,9 +15,7 @@ let worker
export default function unifiedPrettier(options) {
const { Compiler } = this

if (!Compiler) {
throw new Error('unified-prettier needs another compiler to be registered first')
}
assert(Compiler, 'unified-prettier needs another compiler to be registered first')

this.Compiler = (tree, file) => {
/** @type {unknown} */
Expand Down
8 changes: 6 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict'
import assert, { AssertionError } from 'node:assert/strict'
import { test } from 'node:test'

import { unified } from 'unified'
Expand Down Expand Up @@ -85,7 +85,11 @@ test('accept prettier options', () => {
test('error if there is no compiler', () => {
assert.throws(
() => unified().use(unifiedPrettier).freeze(),
new Error('unified-prettier needs another compiler to be registered first')
new AssertionError({
expected: true,
message: 'unified-prettier needs another compiler to be registered first',
operator: '=='
})
)
})

Expand Down

0 comments on commit f7f6527

Please sign in to comment.