Skip to content

Commit e874a5e

Browse files
committed
move safe migration tests to is-safe-migration tests
1 parent d512a41 commit e874a5e

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,26 @@ test('does not replace classes in invalid positions', async () => {
2929
await shouldNotReplace(`<div v-else-if="!border"></div>\n`)
3030
await shouldNotReplace(`<div v-show="!border"></div>\n`)
3131
await shouldNotReplace(`<div x-if="!border"></div>\n`)
32+
33+
await shouldNotReplace(`let notShadow = shadow \n`, 'shadow')
34+
await shouldNotReplace(`{ "foo": shadow.something + ""}\n`, 'shadow')
35+
await shouldNotReplace(`<div v-if="something && shadow"></div>\n`, 'shadow')
36+
await shouldNotReplace(`<div v-else-if="something && shadow"></div>\n`, 'shadow')
37+
await shouldNotReplace(`<div v-show="something && shadow"></div>\n`, 'shadow')
38+
await shouldNotReplace(`<div v-if="shadow || shadow"></div>\n`, 'shadow')
39+
await shouldNotReplace(`<div v-else-if="shadow || shadow"></div>\n`, 'shadow')
40+
await shouldNotReplace(`<div v-show="shadow || shadow"></div>\n`, 'shadow')
41+
await shouldNotReplace(`<div v-if="shadow"></div>\n`, 'shadow')
42+
await shouldNotReplace(`<div v-else-if="shadow"></div>\n`, 'shadow')
43+
await shouldNotReplace(`<div v-show="shadow"></div>\n`, 'shadow')
44+
await shouldNotReplace(`<div x-if="shadow"></div>\n`, 'shadow')
45+
await shouldNotReplace(
46+
`<div style={{filter: 'drop-shadow(30px 10px 4px #4444dd)'}}/>\n`,
47+
'shadow',
48+
)
49+
50+
// Next.js Image placeholder cases
51+
await shouldNotReplace(`<Image placeholder="blur" src="/image.jpg" />`, 'blur')
52+
await shouldNotReplace(`<Image placeholder={'blur'} src="/image.jpg" />`, 'blur')
53+
await shouldNotReplace(`<Image placeholder={blur} src="/image.jpg" />`, 'blur')
3254
})
Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
22
import { expect, test, vi } from 'vitest'
33
import * as versions from '../../utils/version'
4-
import { isSafeMigration } from './is-safe-migration'
54
import { migrateLegacyClasses } from './migrate-legacy-classes'
65
vi.spyOn(versions, 'isMajor').mockReturnValue(true)
76

@@ -44,43 +43,3 @@ test.each([
4443

4544
expect(await migrateLegacyClasses(designSystem, {}, candidate)).toEqual(result)
4645
})
47-
48-
test('does not replace classes in invalid positions', async () => {
49-
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
50-
base: __dirname,
51-
})
52-
53-
async function shouldNotReplace(example: string, candidate = 'shadow') {
54-
let location = {
55-
contents: example,
56-
start: example.indexOf(candidate),
57-
end: example.indexOf(candidate) + candidate.length,
58-
}
59-
60-
// Skip this migration if we think that the migration is unsafe
61-
if (location && !isSafeMigration(candidate, location, designSystem)) {
62-
return candidate
63-
}
64-
65-
expect(await migrateLegacyClasses(designSystem, {}, candidate)).toEqual(candidate)
66-
}
67-
68-
await shouldNotReplace(`let notShadow = shadow \n`)
69-
await shouldNotReplace(`{ "foo": shadow.something + ""}\n`)
70-
await shouldNotReplace(`<div v-if="something && shadow"></div>\n`)
71-
await shouldNotReplace(`<div v-else-if="something && shadow"></div>\n`)
72-
await shouldNotReplace(`<div v-show="something && shadow"></div>\n`)
73-
await shouldNotReplace(`<div v-if="shadow || shadow"></div>\n`)
74-
await shouldNotReplace(`<div v-else-if="shadow || shadow"></div>\n`)
75-
await shouldNotReplace(`<div v-show="shadow || shadow"></div>\n`)
76-
await shouldNotReplace(`<div v-if="shadow"></div>\n`)
77-
await shouldNotReplace(`<div v-else-if="shadow"></div>\n`)
78-
await shouldNotReplace(`<div v-show="shadow"></div>\n`)
79-
await shouldNotReplace(`<div x-if="shadow"></div>\n`)
80-
await shouldNotReplace(`<div style={{filter: 'drop-shadow(30px 10px 4px #4444dd)'}}/>\n`)
81-
82-
// Next.js Image placeholder cases
83-
await shouldNotReplace(`<Image placeholder="blur" src="/image.jpg" />`, 'blur')
84-
await shouldNotReplace(`<Image placeholder={'blur'} src="/image.jpg" />`, 'blur')
85-
await shouldNotReplace(`<Image placeholder={blur} src="/image.jpg" />`, 'blur')
86-
})

0 commit comments

Comments
 (0)