Skip to content

Commit abd7284

Browse files
committed
test: commit utwm vite test case
1 parent 779a49c commit abd7284

File tree

12 files changed

+205
-28
lines changed

12 files changed

+205
-28
lines changed

packages/tailwindcss-patch/test/cache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCacheOptions, mkCacheDirectory, readCache, writeCache } from '../src/cache'
2-
import path from 'path'
2+
import path from 'node:path'
33
import { pkgName } from '../src/constants'
4-
import fs from 'fs'
4+
import fs from 'node:fs'
55
describe('cache', () => {
66
it('getCacheOptions', () => {
77
expect(getCacheOptions).toBeDefined()
@@ -45,7 +45,7 @@ describe('cache', () => {
4545
`{
4646
[ '2',"fuck you",{s:'12}
4747
}`,
48-
'utf-8'
48+
'utf8'
4949
)
5050
expect(fs.existsSync(filepath)).toBe(true)
5151
const cache = readCache({

packages/tailwindcss-patch/test/class.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TailwindcssPatcher } from '../src/class'
2-
import path from 'path'
2+
import path from 'node:path'
33
import { getCss, getTestCase } from './utils'
44
describe('class', () => {
55
it('default', () => {
@@ -35,4 +35,25 @@ describe('class', () => {
3535
expect(set.size).toBeGreaterThan(0)
3636
expect(set.size).toBe(5)
3737
})
38+
39+
it('multiple time process sources', () => {
40+
const twPatcher = new TailwindcssPatcher()
41+
getCss(['text-[100px]'])
42+
let ctxs = twPatcher.getContexts()
43+
expect(ctxs.length).toBe(1)
44+
let set = twPatcher.getClassSet()
45+
expect(set.size).toBeGreaterThan(0)
46+
expect(set.size).toBe(2)
47+
expect(set.has('text-[100px]')).toBe(true)
48+
49+
// 2 times
50+
// 不累加
51+
getCss(['text-[99px]'])
52+
ctxs = twPatcher.getContexts()
53+
expect(ctxs.length).toBe(1)
54+
set = twPatcher.getClassSet()
55+
expect(set.size).toBeGreaterThan(0)
56+
expect(set.size).toBe(2)
57+
expect(set.has('text-[99px]')).toBe(true)
58+
})
3859
})

packages/tailwindcss-patch/test/context.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('common usage', () => {
2929
const set = getClassCacheSet()
3030
expect(set.size).toBeGreaterThan(0)
3131
expect(set.size).toBe(2)
32-
expect(Array.from(set.values())[1]).toBe("bg-[url('https://xxx.webp')]")
32+
expect([...set.values()][1]).toBe("bg-[url('https://xxx.webp')]")
3333
//
3434
})
3535

packages/tailwindcss-patch/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { internalPatch } from '../src/patcher'
22

3-
import path from 'path'
3+
import path from 'node:path'
44
const tailwindcssCasePath = path.resolve(__dirname, 'fixtures')
55
const versionsPkgDir = path.resolve(tailwindcssCasePath, 'versions/package.json')
66

77
function getTailwindcssVersion(str: string) {
88
// eslint-disable-next-line no-useless-escape
9-
const match = /^tailwindcss([\d\.]*)$/.exec(str)
9+
const match = /^tailwindcss([\d.]*)$/.exec(str)
1010
if (match === null) {
1111
// 不是 tailwindcss
1212
return false

packages/tailwindcss-patch/test/inspector.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import path from 'path'
2-
import fs from 'fs'
1+
import path from 'node:path'
2+
import fs from 'node:fs'
33
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from '../src/inspector'
44
const tailwindcssCasePath = path.resolve(__dirname, 'fixtures')
55
const twltsLibPath = path.resolve(tailwindcssCasePath, 'versions/3.3.1/lib')
66

77
describe('inspector', () => {
88
it('inspectPostcssPlugin patch snap', () => {
9-
const rawCode = fs.readFileSync(path.resolve(twltsLibPath, 'plugin.js'), 'utf-8')
9+
const rawCode = fs.readFileSync(path.resolve(twltsLibPath, 'plugin.js'), 'utf8')
1010
const { code, hasPatched } = inspectPostcssPlugin(rawCode)
1111
expect(hasPatched).toBe(false)
1212
expect(code).toMatchSnapshot()
@@ -16,7 +16,7 @@ describe('inspector', () => {
1616
})
1717

1818
it('inspectProcessTailwindFeaturesReturnContext patch snap', () => {
19-
const rawCode = fs.readFileSync(path.resolve(twltsLibPath, 'processTailwindFeatures.js'), 'utf-8')
19+
const rawCode = fs.readFileSync(path.resolve(twltsLibPath, 'processTailwindFeatures.js'), 'utf8')
2020
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(rawCode)
2121
expect(hasPatched).toBe(false)
2222
expect(code).toMatchSnapshot()

packages/tailwindcss-patch/test/patcher.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { getInstalledPkgJsonPath } from '../src/patcher'
2-
import path from 'path'
2+
import path from 'node:path'
33

44
describe('patcher', () => {
55
it('getInstalledPkgJsonPath common options', () => {
66
const pkgJsonPath = getInstalledPkgJsonPath()
77
expect(pkgJsonPath).toBeTruthy()
8-
pkgJsonPath && expect(path.relative(process.cwd(), pkgJsonPath).replace(/\\/g, '/')).toMatchSnapshot()
8+
pkgJsonPath && expect(path.relative(process.cwd(), pkgJsonPath).replaceAll('\\', '/')).toMatchSnapshot()
99
})
1010

1111
it('getInstalledPkgJsonPath baseDir options', () => {

packages/tailwindcss-patch/test/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import postcss from 'postcss'
22
import tailwindcss from 'tailwindcss'
3-
import fs from 'fs'
4-
import path from 'path'
3+
import fs from 'node:fs'
4+
import path from 'node:path'
55

66
export function getTestCase(caseName: string) {
7-
return fs.readFileSync(path.resolve(__dirname, 'fixtures', caseName), 'utf-8')
7+
return fs.readFileSync(path.resolve(__dirname, 'fixtures', caseName), 'utf8')
88
}
99
// @tailwind base;
1010
// @tailwind components;

packages/tailwindcss-patch/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"declarationDir": "dist/types"
5+
"declarationDir": "dist/types",
6+
"lib": [
7+
"ES2021"
8+
]
69
},
710
"include": [
811
"src"

packages/unplugin-tailwindcss-mangle/test/__snapshots__/vite.test.ts.snap

Lines changed: 131 additions & 0 deletions
Large diffs are not rendered by default.

packages/unplugin-tailwindcss-mangle/test/fixtures/vite-repo/tailwind.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path')
22

33
/** @type {import('tailwindcss').Config} */
44
module.exports = {
5-
content: [path.resolve(__dirname, "./src/**/*.{html,js}")],
5+
content: [path.resolve(__dirname, "./src/**/*.{html,js,ts}")],
66
theme: {
77
extend: {},
88
},

0 commit comments

Comments
 (0)