Skip to content

Commit 00ec231

Browse files
committed
Add test
1 parent dae553d commit 00ec231

File tree

1 file changed

+87
-1
lines changed
  • packages/tailwindcss-language-server/tests/env

1 file changed

+87
-1
lines changed

packages/tailwindcss-language-server/tests/env/v4.test.js

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

33
import { expect } from 'vitest'
4-
import { css, defineTest, html, js, json } from '../../src/testing'
4+
import { css, defineTest, html, js, json, symlinkTo } from '../../src/testing'
55
import dedent from 'dedent'
66
import { createClient } from '../utils/client'
77

@@ -666,3 +666,89 @@ defineTest({
666666
})
667667
},
668668
})
669+
670+
defineTest({
671+
// This test *always* passes inside Vitest because our custom version of
672+
// `Module._resolveFilename` is not called. Our custom implementation is
673+
// using enhanced-resolve under the hood which is affected by the `#`
674+
// character issue being considered a fragment identifier.
675+
//
676+
// This most commonly happens when dealing with PNPM packages that point
677+
// to a specific commit hash of a git repository.
678+
//
679+
// To simulate this, we need to:
680+
// - Add a local package to package.json
681+
// - Symlink that local package to a directory with `#` in the name
682+
// - Then run the test in a separate process (`spawn` mode)
683+
//
684+
// We can't use `file:./a#b` because NPM considers `#` to be a fragment
685+
// identifier and will not resolve the path the way we need it to.
686+
name: 'v3: require() works when path is resolved to contain a `#`',
687+
fs: {
688+
'package.json': json`
689+
{
690+
"dependencies": {
691+
"tailwindcss": "3.4.17",
692+
"some-pkg": "file:./packages/some-pkg"
693+
}
694+
}
695+
`,
696+
'tailwind.config.js': js`
697+
module.exports = {
698+
presets: [require('some-pkg/config/tailwind.config.js').default]
699+
}
700+
`,
701+
'packages/some-pkg': symlinkTo('packages/some-pkg#c3f1e'),
702+
'packages/some-pkg#c3f1e/package.json': json`
703+
{
704+
"name": "some-pkg",
705+
"version": "1.0.0",
706+
"main": "index.js"
707+
}
708+
`,
709+
'packages/some-pkg#c3f1e/config/tailwind.config.js': js`
710+
export default {
711+
plugins: [
712+
function ({ addUtilities }) {
713+
addUtilities({
714+
'.example': {
715+
color: 'red',
716+
},
717+
})
718+
}
719+
]
720+
}
721+
`,
722+
},
723+
prepare: async ({ root }) => ({
724+
client: await createClient({
725+
root,
726+
mode: 'spawn',
727+
}),
728+
}),
729+
handle: async ({ client }) => {
730+
let document = await client.open({
731+
lang: 'html',
732+
text: '<div class="example">',
733+
})
734+
735+
// <div class="example">
736+
// ^
737+
let hover = await document.hover({ line: 0, character: 13 })
738+
739+
expect(hover).toEqual({
740+
contents: {
741+
language: 'css',
742+
value: dedent`
743+
.example {
744+
color: red;
745+
}
746+
`,
747+
},
748+
range: {
749+
start: { line: 0, character: 12 },
750+
end: { line: 0, character: 19 },
751+
},
752+
})
753+
},
754+
})

0 commit comments

Comments
 (0)