Skip to content

Commit 5d588ff

Browse files
committed
refactor: make pkg cjs
1 parent 89c11a4 commit 5d588ff

File tree

6 files changed

+20
-42
lines changed

6 files changed

+20
-42
lines changed

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
"repository": "github.com/barelyhuman/node-snapshot",
1313
"license": "MIT",
1414
"author": "reaper<ahoy@barelyhuman.dev>",
15-
"type": "module",
16-
"exports": {
17-
"./package.json": "./package.json",
18-
".": {
19-
"types": "./src/snapshot.d.ts",
20-
"import": "./src/snapshot.js"
21-
}
22-
},
15+
"type": "commonjs",
2316
"main": "./src/snapshot.js",
2417
"types": "./src/snapshot.d.ts",
2518
"files": [
@@ -34,13 +27,13 @@
3427
},
3528
"dependencies": {
3629
"diff": "^5.2.0",
37-
"kleur": "^4.1.5"
30+
"kleur": "^4.1.5",
31+
"pretty-format": "^29.7.0"
3832
},
3933
"devDependencies": {
4034
"@barelyhuman/prettier-config": "^1.1.0",
4135
"bumpp": "^9.4.1",
4236
"prettier": "^3.3.2",
43-
"pretty-format": "^29.7.0",
4437
"publint": "^0.2.8"
4538
}
4639
}

readme.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ a quick and dirty wrapper around node test context for snapshot testing
77
Enthusiatic developers who like to play around with things, **this is for
88
you**!!
99

10-
> [!NOTE]
11-
> This package is **ESM** only
12-
1310
### Installation
1411

1512
```sh
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
exports[`yo 1`]=`"make it rain"`
1+
exports[`yo 1`] = `"make it rain"`
22

3-
exports[`yo 2 1`]=`Object {
3+
exports[`yo 2 1`] = `Object {
44
"name": 3,
55
}`
66

7-
exports[`yo 2 2`]=`Object {
7+
exports[`yo 2 2`] = `Object {
88
"name": 1,
99
}`
1010

11-
exports[`lols 1`]=`Array [
11+
exports[`lols 1`] = `Array [
1212
Object {
1313
"name": 1,
1414
},
1515
Object {
1616
"name": 2,
1717
},
1818
]`
19-

src/snapshot.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { diffTrimmedLines } from 'diff'
2-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
3-
import { createRequire } from 'node:module'
4-
import { dirname, extname, join, relative } from 'node:path'
5-
import { format } from 'pretty-format'
6-
import k from 'kleur'
1+
const { diffTrimmedLines } = require('diff')
2+
const { existsSync, mkdirSync, writeFileSync } = require('node:fs')
3+
const { dirname, extname, join, relative } = require('node:path')
4+
const { format } = require('pretty-format')
5+
const k = require('kleur')
76

87
const ADDED = k.green
98
const REMOVED = k.red
@@ -42,19 +41,14 @@ function getFileName() {
4241
}
4342
}
4443

45-
const require = createRequire(import.meta.url)
46-
4744
let fileTestCounter = new Map()
4845

4946
function getFileCounterKey(filename, testName) {
5047
return `${filename}:${testName}`
5148
}
5249

53-
export function snapshot(
54-
test,
55-
currentValue,
56-
errorMsg = 'Snapshot does not match'
57-
) {
50+
exports.snapshot = snapshot
51+
function snapshot(test, currentValue, errorMsg = 'Snapshot does not match') {
5852
const hasFileDetails = getFileName()
5953
const shouldUpdate = () => Number(process.env.UPDATE_SNAPSHOTS) === 1
6054

tests/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { test } from 'node:test'
2-
import { snapshot } from '../src/snapshot.js'
1+
const { test } = require('node:test')
2+
const { snapshot } = require('../src/snapshot.js')
33

44
test('yo', t => {
55
snapshot(t, 'make it rain')

0 commit comments

Comments
 (0)