Skip to content

Commit

Permalink
enable test in vite/webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Mar 30, 2021
1 parent cd7f3d8 commit 7a8eca1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 66 deletions.
4 changes: 2 additions & 2 deletions test/fixture/vite/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Products } from './products';
import { Greeting } from './greeting';
import { Effect } from './effect';
import { Style } from './styles';
// import { List } from './list';
import { List } from './list';
import { useCounter } from './useCounter';

setup(h);
Expand All @@ -29,7 +29,7 @@ export function App(props) {
<Products />
</StoreProvider>
<Effect />
{/* <List /> */}
<List />
</Style>
)
}
4 changes: 2 additions & 2 deletions test/fixture/webpack/src/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h } from 'preact'
import { setup } from 'goober';
// import { List } from './list.jsx';
import { List } from './list.jsx';
import { Greeting } from './greeting.jsx';
import { StoreProvider } from './context.jsx';
import { Products } from './products.jsx';
Expand Down Expand Up @@ -32,7 +32,7 @@ export function App(props) {
<Products />
</StoreProvider>
<Effect />
{/* <List /> */}
<List />
</Style>
)
}
129 changes: 67 additions & 62 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,39 +151,39 @@ describe('Prefresh integrations', () => {

// TODO: this bugs in next10webpack5 but not webpack 5...
// integration === 'next-webpack5'
//if (integration !== 'next-webpack5') {
test('add file and import it', async () => {
const compPath = path.join(getTempDir(integration), 'src/test.jsx');
await fs.writeFile(
compPath,
`import { h } from 'preact';
export const Tester = () => <p className="tester">Test</p>;`
);

await updateFile('src/app.jsx', content => {
let newContent = 'import { Tester } from "./test.jsx";\n' + content;
newContent = newContent.replace(
`<Test />`,
`<Test />\n <Tester />\n`
if (integration !== 'next-webpack5') {
test('add file and import it', async () => {
const compPath = path.join(getTempDir(integration), 'src/test.jsx');
await fs.writeFile(
compPath,
`import { h } from 'preact';
export const Tester = () => <p className="tester">Test</p>;`
);
return newContent;
});
await timeout(2000);

const testText = await page.$('.tester');
await expectByPolling(() => getText(testText), 'Test');
await updateFile('src/app.jsx', content => {
let newContent = 'import { Tester } from "./test.jsx";\n' + content;
newContent = newContent.replace(
`<Test />`,
`<Test />\n <Tester />\n`
);
return newContent;
});
await timeout(2000);

await updateFile('src/test.jsx', c =>
c.replace(
'<p className="tester">Test</p>',
'<p className="tester">Test2</p>'
)
);
await timeout(2000);
const testText = await page.$('.tester');
await expectByPolling(() => getText(testText), 'Test');

await expectByPolling(() => getText(testText), 'Test2');
});
//}
await updateFile('src/test.jsx', c =>
c.replace(
'<p className="tester">Test</p>',
'<p className="tester">Test2</p>'
)
);
await timeout(2000);

await expectByPolling(() => getText(testText), 'Test2');
});
}

test('custom hook', async () => {
const value = await page.$('.value');
Expand Down Expand Up @@ -313,39 +313,44 @@ describe('Prefresh integrations', () => {
).toBe('rgb(255, 255, 255)');
});

// test('can update in-file HOCs', async () => {
// let listItems = await page.$('#item-list');
// let children = await listItems.$$('div');

// expect(children.length).toEqual(4);
// expect(await getText(children[0])).toMatch('item 0');
// expect(await getText(children[1])).toMatch('item 1');

// await updateFile('src/listItem.jsx', content =>
// content.replace('item {this.props.index}', 'items {this.props.index}')
// );
// await timeout(TIMEOUT);

// listItems = await page.$('#item-list');
// children = await listItems.$$('div');
// expect(children.length).toEqual(4);
// expect(await getText(children[0])).toMatch('items 0');
// expect(await getText(children[1])).toMatch('items 1');

// await updateFile('src/listItem.jsx', content =>
// content.replace(
// 'items {this.props.index}',
// 'item {this.props.index} --'
// )
// );
// await timeout(TIMEOUT);

// listItems = await page.$('#item-list');
// children = await listItems.$$('div');
// expect(children.length).toEqual(4);
// expect(await getText(children[0])).toMatch('item 0 --');
// expect(await getText(children[1])).toMatch('item 1 --');
// });
if (integration === 'vite' || integration === 'webpack') {
test('can update in-file HOCs', async () => {
let listItems = await page.$('#item-list');
let children = await listItems.$$('div');

expect(children.length).toEqual(4);
expect(await getText(children[0])).toMatch('item 0');
expect(await getText(children[1])).toMatch('item 1');

await updateFile('src/listItem.jsx', content =>
content.replace(
'item {this.props.index}',
'items {this.props.index}'
)
);
await timeout(TIMEOUT);

listItems = await page.$('#item-list');
children = await listItems.$$('div');
expect(children.length).toEqual(4);
expect(await getText(children[0])).toMatch('items 0');
expect(await getText(children[1])).toMatch('items 1');

await updateFile('src/listItem.jsx', content =>
content.replace(
'items {this.props.index}',
'item {this.props.index} --'
)
);
await timeout(TIMEOUT);

listItems = await page.$('#item-list');
children = await listItems.$$('div');
expect(children.length).toEqual(4);
expect(await getText(children[0])).toMatch('item 0 --');
expect(await getText(children[1])).toMatch('item 1 --');
});
}
});
});
});

0 comments on commit 7a8eca1

Please sign in to comment.