Skip to content

Commit

Permalink
feat: add jsx support (#50)
Browse files Browse the repository at this point in the history
* feat: add support for tsx files

* remove video
  • Loading branch information
danadajian authored Aug 10, 2022
1 parent 1ce783d commit 1ac5591
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.idea
.DS_Store
cypress/screenshots
cypress/videos
3 changes: 3 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { cypressCodegen } from 'cypress-codegen/dist/plugin';
import { defineConfig } from 'cypress';

export default defineConfig({
screenshotOnRunFailure: false,
video: false,

e2e: {
setupNodeEvents(on, config) {
cypressCodegen(on, config);
Expand Down
17 changes: 17 additions & 0 deletions cypress/commands/custom-mount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';

export const customMount = (Component: React.ReactElement) => {
cy.mount(
<div>
<Component />
</div>
);
};

declare global {
namespace Cypress {
interface Chainable {
customMount(Component: React.ReactElement): Chainable;
}
}
}
25 changes: 25 additions & 0 deletions cypress/component/component-example.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,29 @@ describe('Example Test', () => {
it('should import custom commands in component tests', () => {
cy.functionExample(componentText);
});

it('should dynamically import custom commands from arrow functions', () => {
cy.arrowFunctionExample(componentText);
});

it('should support scoped methods', () => {
cy.contains(componentText).functionExampleScoped(componentText);
});

it('should dynamically import nested custom commands', () => {
cy.nestedExample(componentText);
});

it('should chain custom commands', () => {
cy.log(componentText)
.functionExample(componentText)
.arrowFunctionExample(componentText)
.nestedExample(componentText);
});

it('should support custom mount commands', () => {
const myComponent = () => <>{'Different text'}</>;
cy.customMount(myComponent);
cy.contains('Different text');
});
});
2 changes: 1 addition & 1 deletion src/generate-types-from-abstract-syntax-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { isScopedMethod } from './common';

export const generateTypesFromAbstractSyntaxTree = (filePath: string, prettierConfig?: Options) => {
const contents = readFileSync(resolve(filePath)).toString();
const ast = parse(contents, { sourceType: 'module', plugins: ['typescript'] });
const ast = parse(contents, { sourceType: 'module', plugins: ['typescript', 'jsx'] });
const currentNodes = ast.program.body;
const customCommands = currentNodes
.filter(
Expand Down

0 comments on commit 1ac5591

Please sign in to comment.