Add more tsconfig alias tests (#6812)
This commit is contained in:
parent
99479e6b95
commit
a91e0156ab
12 changed files with 66 additions and 5 deletions
|
@ -34,5 +34,29 @@ describe('Aliases with tsconfig.json', () => {
|
|||
const scripts = $('script').toArray();
|
||||
expect(scripts.length).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it('can load via baseUrl', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#foo').text()).to.equal('foo');
|
||||
expect($('#constants-foo').text()).to.equal('foo');
|
||||
});
|
||||
|
||||
it('can load namespace packages with @* paths', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#namespace').text()).to.equal('namespace');
|
||||
});
|
||||
|
||||
// TODO: fix this https://github.com/withastro/astro/issues/6551
|
||||
it.skip('works in css @import', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
console.log(html);
|
||||
// imported css should be bundled
|
||||
expect(html).to.include('#style-red');
|
||||
expect(html).to.include('#style-blue');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
1
packages/astro/test/fixtures/alias-tsconfig/deps/namespace-package/index.js
vendored
Normal file
1
packages/astro/test/fixtures/alias-tsconfig/deps/namespace-package/index.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const namespace = 'namespace';
|
7
packages/astro/test/fixtures/alias-tsconfig/deps/namespace-package/package.json
vendored
Normal file
7
packages/astro/test/fixtures/alias-tsconfig/deps/namespace-package/package.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@test/namespace-package",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": "./index.js"
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/svelte": "workspace:*",
|
||||
"@test/namespace-package": "workspace:*",
|
||||
"astro": "workspace:*",
|
||||
"svelte": "^3.48.0"
|
||||
}
|
||||
|
|
1
packages/astro/test/fixtures/alias-tsconfig/src/components/Foo.astro
vendored
Normal file
1
packages/astro/test/fixtures/alias-tsconfig/src/components/Foo.astro
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<p id="foo">foo</p>
|
2
packages/astro/test/fixtures/alias-tsconfig/src/components/Style.astro
vendored
Normal file
2
packages/astro/test/fixtures/alias-tsconfig/src/components/Style.astro
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<p id="style-blue">i am blue</p>
|
||||
<p id="style-red">i am red</p>
|
|
@ -1,5 +1,11 @@
|
|||
---
|
||||
import Client from '@components/Client.svelte'
|
||||
import Foo from 'src/components/Foo.astro';
|
||||
import StyleComp from 'src/components/Style.astro';
|
||||
import { namespace } from '@test/namespace-package'
|
||||
import { foo } from 'src/utils/constants';
|
||||
// TODO: support alias in @import https://github.com/withastro/astro/issues/6551
|
||||
// import '@styles/main.css';
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -10,6 +16,10 @@ import Client from '@components/Client.svelte'
|
|||
<body>
|
||||
<main>
|
||||
<Client client:load />
|
||||
<Foo />
|
||||
<StyleComp />
|
||||
<p id="namespace">{namespace}</p>
|
||||
<p id="constants-foo">{foo}</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
|
3
packages/astro/test/fixtures/alias-tsconfig/src/styles/extra.css
vendored
Normal file
3
packages/astro/test/fixtures/alias-tsconfig/src/styles/extra.css
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
#style-red {
|
||||
color: red;
|
||||
}
|
5
packages/astro/test/fixtures/alias-tsconfig/src/styles/main.css
vendored
Normal file
5
packages/astro/test/fixtures/alias-tsconfig/src/styles/main.css
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
@import "@styles/extra.css";
|
||||
|
||||
#style-blue {
|
||||
color: blue;
|
||||
}
|
1
packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js
vendored
Normal file
1
packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const foo = 'foo'
|
|
@ -5,12 +5,13 @@
|
|||
"@components/*": [
|
||||
"src/components/*"
|
||||
],
|
||||
"@layouts/*": [
|
||||
"src/layouts/*"
|
||||
],
|
||||
"@assets/*": [
|
||||
"src/assets/*"
|
||||
"@styles/*": [
|
||||
"src/styles/*"
|
||||
],
|
||||
// this can really trip up namespaced packages
|
||||
"@*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1270,13 +1270,18 @@ importers:
|
|||
packages/astro/test/fixtures/alias-tsconfig:
|
||||
specifiers:
|
||||
'@astrojs/svelte': workspace:*
|
||||
'@test/namespace-package': workspace:*
|
||||
astro: workspace:*
|
||||
svelte: ^3.48.0
|
||||
dependencies:
|
||||
'@astrojs/svelte': link:../../../../integrations/svelte
|
||||
'@test/namespace-package': link:deps/namespace-package
|
||||
astro: link:../../..
|
||||
svelte: 3.55.1
|
||||
|
||||
packages/astro/test/fixtures/alias-tsconfig/deps/namespace-package:
|
||||
specifiers: {}
|
||||
|
||||
packages/astro/test/fixtures/api-routes:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
|
|
Loading…
Reference in a new issue