Skip to content

Commit b1fd7d1

Browse files
committed
wip
1 parent 1961cc9 commit b1fd7d1

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

+87-1
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+
name: 'v3: require() works when path is resolved to contain a `#`',
672+
fs: {
673+
'package.json': json`
674+
{
675+
"dependencies": {
676+
"tailwindcss": "3.4.17",
677+
"some-pkg": "file:./packages/some-pkg"
678+
}
679+
}
680+
`,
681+
'tailwind.config.js': js`
682+
module.exports = {
683+
presets: [require('some-pkg/config/tailwind.config.js').default]
684+
}
685+
`,
686+
'packages/some-pkg': symlinkTo('packages/some-pkg#c3f1e'),
687+
'packages/some-pkg#c3f1e/package.json': json`
688+
{
689+
"name": "some-pkg",
690+
"version": "1.0.0",
691+
"main": "index.js"
692+
}
693+
`,
694+
'packages/some-pkg#c3f1e/config/tailwind.config.js': js`
695+
export default {
696+
plugins: [
697+
function ({ addUtilities }) {
698+
addUtilities({
699+
'.example': {
700+
color: 'red',
701+
},
702+
})
703+
}
704+
]
705+
}
706+
`,
707+
},
708+
prepare: async ({ root }) => ({
709+
client: await createClient({
710+
root,
711+
// This test *always* passes inside Vitest because our custom version of
712+
// `Module._resolveFilename` is not called. Our custom implementation is
713+
// using enhanced-resolve under the hood which is affected by the `#`
714+
// character issue being considered a fragment identifier.
715+
//
716+
// This most commonly happens when dealing with PNPM packages that point
717+
// to a specific commit hash of a git repository.
718+
//
719+
// To simulate this, we need to:
720+
// - Add a local package to package.json
721+
// - Symlink that local package to a directory with `#` in the name
722+
// - Then run the test in a separate process (`spawn` mode)
723+
//
724+
// We can't use `file:./a#b` because NPM considers `#` to be a fragment
725+
// identifier and will not resolve the path the way we need it to.
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)