From db0851cb796d361e81ec1fe35ddff3f961c6484a Mon Sep 17 00:00:00 2001 From: Mike North Date: Thu, 26 Oct 2023 08:24:49 -0500 Subject: [PATCH] E2E testing for interactive code snippets (#948) * e2e testing for generated code snippets * Parcel ts-utils --- packages/chat/package.json | 1 + .../e2e/code-snippets/code-snippets.cy.ts | 37 +++++++++++++++++++ yarn.lock | 14 +------ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 packages/website/cypress/e2e/code-snippets/code-snippets.cy.ts diff --git a/packages/chat/package.json b/packages/chat/package.json index 442567c8b..9dbb444b5 100644 --- a/packages/chat/package.json +++ b/packages/chat/package.json @@ -9,6 +9,7 @@ "browserslist": "> 0.5%, last 2 versions, not dead", "dependencies": { "@parcel/core": "^2.10.0", + "@parcel/ts-utils": "^2.10.1", "date-fns": "^2.30.0", "execa": "^8.0.1", "express": "^4.18.2", diff --git a/packages/website/cypress/e2e/code-snippets/code-snippets.cy.ts b/packages/website/cypress/e2e/code-snippets/code-snippets.cy.ts new file mode 100644 index 000000000..677396c42 --- /dev/null +++ b/packages/website/cypress/e2e/code-snippets/code-snippets.cy.ts @@ -0,0 +1,37 @@ +/// + +describe('code snippet interactions', () => { + beforeEach(() => { + cy.visit('http://localhost:8000/course/fundamentals-v4/07-interfaces-and-type-aliases/').waitForRouteChange() + }) + + it('Code snippet is found', () => { + // Code snippet found + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(6)').should('exist').should('contain.text', 'function printAmount') + }) + + it('"Popover" tooltips from ^? are present', () => { + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(6) :nth-child(10) > .popover').should('contain.text', 'currency: string') + }) + + it('Hover tooltips work', () => { + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(6) data-lsp[lsp="function printAmount(amt: Amount): void"]') + .should('exist').trigger('mouseover') + cy.get('#twoslash-mouse-hover-info').should('contain.text', "function printAmount(amt: Amount): void") + }) + it('Rendered errors work', () => { + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(15)').should('exist').should('contain.text', 'type Amount') + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(15) code > span.error:nth-child(2)') + .should('exist') + .should('contain.text', 'Duplicate identifier') + + }) + it('Code complete for |^ works', () => { + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(21)').should('exist').should('contain.text', 'newYearsEve') + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(21) .inline-completions').should('exist').should('contain.text', 'getDay') + }) + it('Code highlighting works', () => { + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(49)').should('exist').should('contain.text', 'jumpToHeight') + cy.get('.post-body > .shiki.twoslash.lsp:nth-child(49) .highlight').should('exist').should('contain.text', 'string') + }) +}) diff --git a/yarn.lock b/yarn.lock index ac42313ac..f455c92c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3918,18 +3918,7 @@ __metadata: languageName: node linkType: hard -"@parcel/ts-utils@npm:2.10.0": - version: 2.10.0 - resolution: "@parcel/ts-utils@npm:2.10.0" - dependencies: - nullthrows: ^1.1.1 - peerDependencies: - typescript: ">=3.0.0" - checksum: 7151fef86f358e780db3153405598193a7e816ced2de1c61ed3250a04e41a759b4dee959db02630fee8a4a3b4b4561e4e04de7abb1dd99fba635bd3452f7f960 - languageName: node - linkType: hard - -"@parcel/ts-utils@npm:2.10.1": +"@parcel/ts-utils@npm:2.10.1, @parcel/ts-utils@npm:^2.10.1": version: 2.10.1 resolution: "@parcel/ts-utils@npm:2.10.1" dependencies: @@ -7582,6 +7571,7 @@ __metadata: "@parcel/transformer-inline-string": ^2.10.0 "@parcel/transformer-typescript-tsc": ^2.10.0 "@parcel/transformer-typescript-types": ^2.10.0 + "@parcel/ts-utils": ^2.10.1 "@types/express": ^4.17.19 "@types/json-server": ^0.14.5 "@types/react": ^18.2.28