Skip to content

Commit

Permalink
add a TypeScript fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 committed Jul 10, 2023
1 parent ea62911 commit ad9be11
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cypress/e2e/smoke.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ describe('Smoke', () => {

assertPreviewContains('Foo\nFoo\nBar');
});

it('preview mode works with TypeScript components', () => {
cy.visit(
'http://localhost:9002/preview#?code=N4Igxg9gJgpiBcIA8AxCEB8r1YEIEMAnAei2LUyXJxAF8g'
);

assertPreviewContains('Foo\nFoo\nBar');
});
});
4 changes: 2 additions & 2 deletions cypress/e2e/snippets.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Snippets', () => {
assertCodePaneLineCount(8);

// Browse snippetlist
assertSnippetCount(4);
assertSnippetCount(5);
mouseOverSnippet(0);
assertFirstFrameContains('Initial code\nFoo\nFoo');
mouseOverSnippet(1);
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('Snippets', () => {
assertCodePaneLineCount(8);

// Browse snippetlist
assertSnippetCount(4);
assertSnippetCount(5);
filterSnippets('{downarrow}');
assertFirstFrameContains('Initial code\nFoo\nFoo');
filterSnippets('{downarrow}');
Expand Down
1 change: 0 additions & 1 deletion cypress/placeholder.ts

This file was deleted.

5 changes: 5 additions & 0 deletions cypress/projects/basic/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ export default [
name: 'Blue',
code: '<Bar color="blue">Blue Bar</Bar>',
},
{
group: 'Scope',
name: 'hello world',
code: '<Foo>{hello()} {world()}</Foo>',
},
];
2 changes: 2 additions & 0 deletions cypress/projects/typescript/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Foo } from './components/Foo';
export { Bar } from './components/Bar';
13 changes: 13 additions & 0 deletions cypress/projects/typescript/components/Bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type React from 'react';
import { parent } from './styles';

type Props = {
color: 'red' | 'blue';
children: React.ReactNode;
};

export const Bar: React.FC<Props> = ({ color = 'black', children }) => (
<div style={{ color }}>
Bar{children ? <div style={parent}>{children}</div> : null}
</div>
);
13 changes: 13 additions & 0 deletions cypress/projects/typescript/components/Foo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type React from 'react';
import { parent } from './styles';

type Props = {
color: 'red' | 'blue';
children: React.ReactNode;
};

export const Foo: React.FC<Props> = ({ color = 'black', children }) => (
<div style={{ color }}>
Foo{children ? <div style={parent}>{children}</div> : null}
</div>
);
4 changes: 4 additions & 0 deletions cypress/projects/typescript/components/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const parent = {
border: '4px solid currentColor',
padding: '10px 10px 10px 15px',
};
31 changes: 31 additions & 0 deletions cypress/projects/typescript/playroom.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
components: './components.ts',
snippets: './snippets.ts',
outputPath: './dist',
openBrowser: false,
storageKey: 'playroom-example-typescript',
webpackConfig: () => ({
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [
require.resolve('@babel/preset-env'),
[
require.resolve('@babel/preset-react'),
{ runtime: 'automatic' },
],
],
},
},
],
},
],
},
}),
};
22 changes: 22 additions & 0 deletions cypress/projects/typescript/snippets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default [
{
group: 'Foo',
name: 'Default',
code: '<Foo>Foo</Foo>',
},
{
group: 'Foo',
name: 'Red',
code: '<Foo color="red">Red Foo</Foo>',
},
{
group: 'Bar',
name: 'Default',
code: '<Bar>Bar</Bar>',
},
{
group: 'Bar',
name: 'Blue',
code: '<Bar color="blue">Blue Bar</Bar>',
},
];
18 changes: 18 additions & 0 deletions cypress/projects/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
"moduleResolution": "node",
"module": "es2022",
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"resolveJsonModule": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": ["dom", "es2022"],
"target": "es2022"
}
}
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
"playroom": "bin/cli.js"
},
"scripts": {
"cypress": "start-server-and-test build-and-serve:all '9000|9001' 'cypress run'",
"cypress:dev": "start-server-and-test start:all '9000|9001' 'cypress open --browser chrome --e2e'",
"cypress": "start-server-and-test build-and-serve:all '9000|9001|9002' 'cypress run'",
"cypress:dev": "start-server-and-test start:all '9000|9001|9002' 'cypress open --browser chrome --e2e'",
"cypress:verify": "cypress verify",
"start:basic": "./bin/cli.js start --config cypress/projects/basic/playroom.config.js",
"build:basic": "./bin/cli.js build --config cypress/projects/basic/playroom.config.js",
"serve:basic": "PORT=9000 serve --no-request-logging cypress/projects/basic/dist",
"start:themed": "./bin/cli.js start --config cypress/projects/themed/playroom.config.js",
"build:themed": "./bin/cli.js build --config cypress/projects/themed/playroom.config.js",
"serve:themed": "PORT=9001 serve --config ../serve.json --no-request-logging cypress/projects/themed/dist",
"start:all": "concurrently 'npm:start:basic' 'npm:start:themed'",
"build:all": "concurrently 'npm:build:basic' 'npm:build:themed'",
"serve:all": "concurrently 'npm:serve:basic' 'npm:serve:themed'",
"start:typescript": "./bin/cli.js start --config cypress/projects/typescript/playroom.config.js",
"build:typescript": "./bin/cli.js build --config cypress/projects/typescript/playroom.config.js",
"serve:typescript": "PORT=9002 serve --no-request-logging cypress/projects/typescript/dist",
"start:all": "concurrently 'npm:start:*(!all)'",
"build:all": "concurrently 'npm:build:*(!all)'",
"serve:all": "concurrently 'npm:serve:*(!all)'",
"build-and-serve:all": "pnpm build:all && pnpm serve:all",
"lint": "concurrently 'npm:lint:*'",
"lint:eslint": "eslint --cache .",
Expand Down

0 comments on commit ad9be11

Please sign in to comment.