Skip to content

Commit

Permalink
E2E testing for interactive code snippets (#948)
Browse files Browse the repository at this point in the history
* e2e testing for generated code snippets

* Parcel ts-utils
  • Loading branch information
mike-north authored Oct 26, 2023
1 parent 9b7acd4 commit db0851c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions packages/website/cypress/e2e/code-snippets/code-snippets.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />

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')
})
})
14 changes: 2 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit db0851c

Please sign in to comment.