Skip to content

Commit

Permalink
test: move translation API tests to node:test (#659)
Browse files Browse the repository at this point in the history
This test-only change drops Brittle from our translation API tests and
replaces it with `node:test` and `node:assert`.
  • Loading branch information
EvanHahn authored May 23, 2024
1 parent eec06e5 commit 9ff33f9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/translation-api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'brittle'
import test from 'node:test'
import assert from 'node:assert/strict'
import TranslationApi, {
ktranslatedLanguageCodeToSchemaNames,
} from '../src/translation-api.js'
Expand All @@ -13,7 +14,7 @@ import { IndexWriter } from '../src/index-writer/index.js'
import RAM from 'random-access-memory'
import { hashObject } from '../src/utils.js'

test(`translation api - put() and get()`, async (t) => {
test('translation api - put() and get()', async () => {
const api = setup()

const doc = {
Expand All @@ -31,7 +32,7 @@ test(`translation api - put() and get()`, async (t) => {
...api[ktranslatedLanguageCodeToSchemaNames].entries(),
].length

t.is(
assert.equal(
mapEntriesLength,
0,
'the map we use to caching translations is empty before calling put'
Expand All @@ -43,8 +44,8 @@ test(`translation api - put() and get()`, async (t) => {
const { docId } = await api.put(doc)
api.index(doc)

t.ok(docId, `putting a translation doc works`)
t.is(
assert(docId, 'putting a translation doc works')
assert.equal(
docId,
expectedDocId,
'the docId is built as a hash from the doc correctly'
Expand All @@ -53,20 +54,20 @@ test(`translation api - put() and get()`, async (t) => {
mapEntriesLength = [...api[ktranslatedLanguageCodeToSchemaNames].entries()]
.length

t.is(
assert.equal(
mapEntriesLength,
1,
'after calling api.index(), the map now has some elements in it'
)
t.ok(
assert(
api[ktranslatedLanguageCodeToSchemaNames].get('es')?.has('field'),
`we've effectively have fields in spanish`
)

/* eslint-disable no-unused-vars */
const { schemaName, message: msg, ...docToGet } = doc

t.is(
assert.equal(
(await api.get(docToGet)).length,
1,
`using the doc without schema name to get the translation works`
Expand All @@ -85,7 +86,7 @@ test(`translation api - put() and get()`, async (t) => {

await api.put(newDoc)

t.is(
assert.equal(
(
await api.get({
schemaNameRef: 'field',
Expand Down

0 comments on commit 9ff33f9

Please sign in to comment.