Skip to content

Commit

Permalink
Add more tsconfig alias tests (#6812)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Apr 10, 2023
1 parent 99479e6 commit a91e015
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 5 deletions.
24 changes: 24 additions & 0 deletions packages/astro/test/alias-tsconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const namespace = 'namespace';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@test/namespace-package",
"version": "0.0.0",
"private": true,
"type": "module",
"exports": "./index.js"
}
1 change: 1 addition & 0 deletions packages/astro/test/fixtures/alias-tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/svelte": "workspace:*",
"@test/namespace-package": "workspace:*",
"astro": "workspace:*",
"svelte": "^3.48.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p id="foo">foo</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p id="style-blue">i am blue</p>
<p id="style-red">i am red</p>
10 changes: 10 additions & 0 deletions packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#style-red {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "@styles/extra.css";

#style-blue {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'foo'
11 changes: 6 additions & 5 deletions packages/astro/test/fixtures/alias-tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"@components/*": [
"src/components/*"
],
"@layouts/*": [
"src/layouts/*"
],
"@assets/*": [
"src/assets/*"
"@styles/*": [
"src/styles/*"
],
// this can really trip up namespaced packages
"@*": [
"src/*"
]
}
}
}
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a91e015

Please sign in to comment.