Skip to content

Commit 0b5765f

Browse files
committed
feat: rename packages/test-node to packages/test-js
1 parent 453987c commit 0b5765f

File tree

7 files changed

+75
-4
lines changed

7 files changed

+75
-4
lines changed

bun.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"tsconfig": "workspace:*",
3434
},
3535
},
36-
"packages/test-node": {
37-
"name": "test-node",
36+
"packages/test-js": {
37+
"name": "test-js",
3838
"devDependencies": {
3939
"@types/bun": "catalog:default",
4040
"tsconfig": "workspace:*",
@@ -365,7 +365,7 @@
365365

366366
"sucrase": ["sucrase@3.35.0", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.2", "commander": "^4.0.0", "glob": "^10.3.10", "lines-and-columns": "^1.1.6", "mz": "^2.7.0", "pirates": "^4.0.1", "ts-interface-checker": "^0.1.9" }, "bin": { "sucrase": "bin/sucrase", "sucrase-node": "bin/sucrase-node" } }, "sha512-8EbVDiu9iN/nESwxeSxDKe0dunta1GOlHufmSSXxMD2z2/tMZpDMpvXQGsc+ajGo8y2uYUmixaSRUc/QPoQ0GA=="],
367367

368-
"test-node": ["test-node@workspace:packages/test-node"],
368+
"test-js": ["test-js@workspace:packages/test-js"],
369369

370370
"thenify": ["thenify@3.3.1", "", { "dependencies": { "any-promise": "^1.0.0" } }, "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw=="],
371371

File renamed without changes.

packages/test-js/index.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// biome-ignore-all lint/performance/noDynamicNamespaceImportAccess: test file
2+
3+
import { describe, expect, test } from 'bun:test'
4+
import fs from 'node:fs'
5+
import * as source from 'src/index.ts'
6+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7+
// @ts-expect-error
8+
import * as mjs from '../../dist/mjs/index.js'
9+
10+
const exportDataList: Partial<keyof typeof source>[] = ['continents', 'countries', 'languages']
11+
const exportFnList: Partial<keyof typeof source>[] = ['getEmojiFlag']
12+
13+
function evalIIFE(name = 'Countries') {
14+
const script = fs.readFileSync('../../dist/index.iife.js', { encoding: 'utf-8' })
15+
// biome-ignore lint/security/noGlobalEval: -
16+
eval(`this.${name} = (function () { ${script}\nreturn ${name}})()`)
17+
}
18+
19+
describe('dist', () => {
20+
test('has proper CJS ES6 export', () => {
21+
expect(typeof mjs).toBe('object')
22+
23+
for (const prop of exportFnList) {
24+
expect(Object.hasOwn(mjs, prop)).toBe(true)
25+
}
26+
27+
for (const prop of exportDataList) {
28+
expect(Object.hasOwn(mjs, prop)).toBe(true)
29+
30+
const cjsKeys = Object.keys(mjs[prop])
31+
const srcKeys = Object.keys(source[prop])
32+
expect(cjsKeys).toEqual(srcKeys)
33+
}
34+
})
35+
36+
test('all English country names should contain only A-Z characters', () => {
37+
const nameReg = /^[a-z\s.()-]+$/i
38+
const nonAZ: string[] = []
39+
for (const c of Object.values(source.countries)) {
40+
if (!nameReg.test(c.name)) {
41+
nonAZ.push(c.name)
42+
}
43+
}
44+
45+
// It helps see incorrect names right away in logs
46+
expect(nonAZ).toEqual([])
47+
})
48+
49+
test('loads ES6 <script> properly', () => {
50+
const context: { Countries?: typeof source } = {}
51+
evalIIFE.call(context)
52+
53+
const contextCountries = context.Countries
54+
55+
expect(contextCountries).toBeTruthy()
56+
expect(contextCountries).toBeObject()
57+
58+
for (const prop of exportFnList) {
59+
expect(contextCountries).toHaveProperty(prop)
60+
}
61+
62+
for (const prop of exportDataList) {
63+
expect(contextCountries).toHaveProperty(prop)
64+
65+
// biome-ignore lint/style/noNonNullAssertion: -
66+
const windowProps = Object.keys(contextCountries![prop]) as string[]
67+
const dataProps = Object.keys(source[prop]) as string[]
68+
expect(windowProps).toEqual(dataProps)
69+
}
70+
})
71+
})

packages/test-node/package.json renamed to packages/test-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "test-node",
2+
"name": "test-js",
33
"type": "module",
44
"devDependencies": {
55
"@types/bun": "catalog:default",
File renamed without changes.

0 commit comments

Comments
 (0)