Skip to content

Commit

Permalink
Merge pull request #129 from dcastil/feature/96/add-test-for-package-…
Browse files Browse the repository at this point in the history
…exports

Add tests to check actual CJS and ESM package exports
  • Loading branch information
dcastil authored Aug 13, 2022
2 parents f5d2c2c + 184234d commit 1236e8f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"extends": ["plugin:jest/recommended", "plugin:jest/style"]
},
{
"files": ["scripts/**/*.js"],
"files": ["scripts/**/*.?(m)js"],
"rules": {
"no-console": "off"
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
name: build-output
path: dist
if-no-files-found: error
- run: yarn test:exports
- run: yarn size
- uses: JS-DevTools/npm-publish@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ jobs:
name: build-output
path: dist
if-no-files-found: error
- run: yarn test:exports
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"scripts": {
"build": "dts build",
"test": "dts test",
"test:exports": "node scripts/test-built-package-exports.js && node scripts/test-built-package-exports.mjs",
"lint": "eslint --max-warnings 0 '**'",
"size": "size-limit",
"preversion": "if [ -n \"$DANYS_MACHINE\" ]; then git checkout main && git pull; fi",
Expand Down
11 changes: 11 additions & 0 deletions scripts/test-built-package-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require('assert')

const { twMerge } = require('..')

assert(twMerge() === '')
assert(
twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') ===
'hover:bg-dark-red p-3 bg-[#B91C1C]'
)

console.log('[tailwind-merge] Tests for built CJS package exports passed.')
12 changes: 12 additions & 0 deletions scripts/test-built-package-exports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import assert from 'assert'

// Not ideal, but there seems to be no way to point the import resolver to the package.json file if this isn't a npm package.
import { twMerge } from '../dist/tailwind-merge.mjs'

assert(twMerge() === '')
assert(
twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') ===
'hover:bg-dark-red p-3 bg-[#B91C1C]'
)

console.log('[tailwind-merge] Tests for built ESM package exports passed.')

0 comments on commit 1236e8f

Please sign in to comment.