-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests: Special chars in component import paths (#4263)
* Add tests: Special chars in component import paths * Fix ESLint warnings, add Windows dev exclusion * Crude fix * chore: update compiler * chore: bump compiler * fix: remove decodeURI * Fix tests and skip them for now Co-authored-by: Princesseuh <[email protected]> Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
65885e2
commit 57fafc7
Showing
14 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/special-chars-in-component-imports/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import react from '@astrojs/react'; | ||
import mdx from '@astrojs/mdx'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [react(), mdx()], | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/special-chars-in-component-imports/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@test/special-chars-in-component-imports", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/mdx": "workspace:*", | ||
"@astrojs/react": "workspace:*", | ||
"astro": "workspace:*", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...est/fixtures/special-chars-in-component-imports/src/components/^--with-carets/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...test/fixtures/special-chars-in-component-imports/src/components/and-rockets-🚀/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...st/fixtures/special-chars-in-component-imports/src/components/now-100%-better/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...t/fixtures/special-chars-in-component-imports/src/components/with some spaces/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...tures/special-chars-in-component-imports/src/components/with-(round-brackets)/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ures/special-chars-in-component-imports/src/components/with-[square-brackets]/Counter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { useState } from 'react'; | ||
|
||
export default function Counter ({ id }) { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div id={id}> | ||
<div>{id}: {count}</div> | ||
<button type="button" onClick={() => setCount(count+1)}>Increment</button> | ||
</div> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/astro/test/fixtures/special-chars-in-component-imports/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
import CaretCounter from '../components/^--with-carets/Counter'; | ||
import RocketCounter from '../components/and-rockets-🚀/Counter'; | ||
import PercentCounter from '../components/now-100%-better/Counter'; | ||
import SpaceCounter from '../components/with some spaces/Counter'; | ||
import RoundBracketCounter from '../components/with-(round-brackets)/Counter'; | ||
import SquareBracketCounter from '../components/with-[square-brackets]/Counter'; | ||
--- | ||
<html> | ||
<body> | ||
<h1>Special chars in component import paths from an .astro file</h1> | ||
<CaretCounter id="caret" client:visible /> | ||
<RocketCounter id="rocket" client:visible /> | ||
<PercentCounter id="percent" client:visible /> | ||
<SpaceCounter id="space" client:visible /> | ||
<RoundBracketCounter id="round-bracket" client:visible /> | ||
<SquareBracketCounter id="square-bracket" client:visible /> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/special-chars-in-component-imports/src/pages/mdx.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import CaretCounter from '../components/^--with-carets/Counter' | ||
import RocketCounter from '../components/and-rockets-🚀/Counter' | ||
import PercentCounter from '../components/now-100%-better/Counter' | ||
import SpaceCounter from '../components/with some spaces/Counter' | ||
import RoundBracketCounter from '../components/with-(round-brackets)/Counter' | ||
import SquareBracketCounter from '../components/with-[square-brackets]/Counter' | ||
|
||
# Special chars in component import paths from an .mdx file | ||
|
||
<CaretCounter id="caret" client:visible /> | ||
<RocketCounter id="rocket" client:visible /> | ||
<PercentCounter id="percent" client:visible /> | ||
<SpaceCounter id="space" client:visible /> | ||
<RoundBracketCounter id="round-bracket" client:visible /> | ||
<SquareBracketCounter id="square-bracket" client:visible /> |
126 changes: 126 additions & 0 deletions
126
packages/astro/test/special-chars-in-component-imports.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { expect } from 'chai'; | ||
import { load as cheerioLoad } from 'cheerio'; | ||
import { isWindows, loadFixture } from './test-utils.js'; | ||
|
||
describe.skip('Special chars in component import paths', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
const componentIds = ['caret', 'rocket', 'percent', 'space', 'round-bracket', 'square-bracket']; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/special-chars-in-component-imports/', | ||
}); | ||
}); | ||
|
||
describe('build', () => { | ||
before(async () => { | ||
await fixture.build(); | ||
}); | ||
|
||
it('Build succeeds', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
expect(html).to.contain('<html>'); | ||
}); | ||
|
||
it('Special chars in imports work from .astro files', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerioLoad(html); | ||
|
||
// Test 1: Correct page | ||
expect($('h1').text()).to.contain('.astro'); | ||
|
||
// Test 2: All components exist | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId}`), `Component #${componentId} does not exist`).to.have.lengthOf(1); | ||
}); | ||
|
||
// Test 3: Component contents were rendered properly | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId} > div`).text()).to.equal(`${componentId}: 0`); | ||
}); | ||
|
||
// Test 4: There is an island for each component | ||
expect($('astro-island[uid]')).to.have.lengthOf(componentIds.length); | ||
}); | ||
|
||
it('Special chars in imports work from .mdx files', async () => { | ||
const html = await fixture.readFile('/mdx/index.html'); | ||
const $ = cheerioLoad(html); | ||
|
||
// Test 1: Correct page | ||
expect($('h1').text()).to.contain('.mdx'); | ||
|
||
// Test 2: All components exist | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId}`), `Component #${componentId} does not exist`).to.have.lengthOf(1); | ||
}); | ||
|
||
// Test 3: Component contents were rendered properly | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId} > div`).text()).to.equal(`${componentId}: 0`); | ||
}); | ||
|
||
// Test 4: There is an island for each component | ||
expect($('astro-island[uid]')).to.have.lengthOf(componentIds.length); | ||
}); | ||
|
||
}); | ||
|
||
if (isWindows) return; | ||
|
||
describe('dev', () => { | ||
let devServer; | ||
|
||
before(async () => { | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('Special chars in imports work from .astro files', async () => { | ||
const html = await fixture.fetch('/').then((res) => res.text()); | ||
const $ = cheerioLoad(html); | ||
|
||
// Test 1: Correct page | ||
expect($('h1').text()).to.contain('.astro'); | ||
|
||
// Test 2: All components exist | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId}`), `Component #${componentId} does not exist`).to.have.lengthOf(1); | ||
}); | ||
|
||
// Test 3: Component contents were rendered properly | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId} > div`).text()).to.equal(`${componentId}: 0`); | ||
}); | ||
|
||
// Test 4: There is an island for each component | ||
expect($('astro-island[uid]')).to.have.lengthOf(componentIds.length); | ||
}); | ||
|
||
it('Special chars in imports work from .mdx files', async () => { | ||
const html = await fixture.fetch('/mdx').then((res) => res.text()); | ||
const $ = cheerioLoad(html); | ||
|
||
// Test 1: Correct page | ||
expect($('h1').text()).to.contain('.mdx'); | ||
|
||
// Test 2: All components exist | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId}`), `Component #${componentId} does not exist`).to.have.lengthOf(1); | ||
}); | ||
|
||
// Test 3: Component contents were rendered properly | ||
componentIds.forEach((componentId) => { | ||
expect($(`#${componentId} > div`).text()).to.equal(`${componentId}: 0`); | ||
}); | ||
|
||
// Test 4: There is an island for each component | ||
expect($('astro-island[uid]')).to.have.lengthOf(componentIds.length); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.