From 276f9844f88fcfd64e571f62e667b3c781c51b6b Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 2 Feb 2024 14:14:30 +0800 Subject: [PATCH 1/4] docs: fix typos --- docs/plugins/feed/config.md | 4 ++-- docs/zh/plugins/copy-code.md | 2 +- docs/zh/plugins/feed/config.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/plugins/feed/config.md b/docs/plugins/feed/config.md index e63efa67a3..68aec5b112 100644 --- a/docs/plugins/feed/config.md +++ b/docs/plugins/feed/config.md @@ -83,9 +83,9 @@ A custom filter function, used to filter feed items. - Default: ```ts - // compareDate is from vuepress-shared + // dateSorter is from @vuepress/helper ;(pageA: Page, pageB: Page): number => - compareDate( + dateSorter( pageA.data.git?.createdTime ? new Date(pageA.data.git?.createdTime) : pageA.frontmatter.date, diff --git a/docs/zh/plugins/copy-code.md b/docs/zh/plugins/copy-code.md index 2da24bbb5b..89cc51917a 100644 --- a/docs/zh/plugins/copy-code.md +++ b/docs/zh/plugins/copy-code.md @@ -24,7 +24,7 @@ export default { } ``` -## 使用方法 +## 选项 ### selector diff --git a/docs/zh/plugins/feed/config.md b/docs/zh/plugins/feed/config.md index 0b6cbf91aa..b269c061c6 100644 --- a/docs/zh/plugins/feed/config.md +++ b/docs/zh/plugins/feed/config.md @@ -83,9 +83,9 @@ - 默认值: ```ts - // compareDate 来源于 vuepress-shared + // dateSorter 来源于 @vuepress/helper ;(pageA, pageB): number => - compareDate( + dateSorter( pageA.data.git?.createdTime ? new Date(pageA.data.git?.createdTime) : pageA.frontmatter.date, From 36a2abe8f49a7500ac23c44dea56f66c331840f0 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 2 Feb 2024 14:14:54 +0800 Subject: [PATCH 2/4] fix(plugin-reading-time): remove noExternal declare --- plugins/plugin-reading-time/src/node/readingTimePlugin.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/plugin-reading-time/src/node/readingTimePlugin.ts b/plugins/plugin-reading-time/src/node/readingTimePlugin.ts index 1adef272ac..8848e3444c 100644 --- a/plugins/plugin-reading-time/src/node/readingTimePlugin.ts +++ b/plugins/plugin-reading-time/src/node/readingTimePlugin.ts @@ -32,10 +32,7 @@ export const readingTimePlugin = }, extendsBundlerOptions: (bundlerOptions: unknown, app): void => { - addViteSsrNoExternal(bundlerOptions, app, [ - '@vuepress/helper', - 'vuepress-shared', - ]) + addViteSsrNoExternal(bundlerOptions, app, '@vuepress/helper') }, } } From 1f59b1ffafff348182234919394a1d13cd5dc1ef Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 2 Feb 2024 14:28:07 +0800 Subject: [PATCH 3/4] test(e2e): improve tests --- e2e/docs/copy-code/README.md | 6 ++ e2e/tests/plugin-copy-code/copy-code.cy.ts | 19 ++-- e2e/tests/plugin-feed/feed.cy.ts | 114 +++++++++++---------- e2e/tests/plugin-seo/seo.cy.ts | 107 +++++++++---------- e2e/tests/theme-default/home.cy.ts | 42 ++++---- e2e/tests/theme-default/navbar.cy.ts | 10 +- e2e/tests/theme-default/sidebar.cy.ts | 53 ++++------ 7 files changed, 178 insertions(+), 173 deletions(-) create mode 100644 e2e/docs/copy-code/README.md diff --git a/e2e/docs/copy-code/README.md b/e2e/docs/copy-code/README.md new file mode 100644 index 0000000000..abc7bd5345 --- /dev/null +++ b/e2e/docs/copy-code/README.md @@ -0,0 +1,6 @@ +# Copy code + +```ts +const a = 1 +const b = 2 +``` diff --git a/e2e/tests/plugin-copy-code/copy-code.cy.ts b/e2e/tests/plugin-copy-code/copy-code.cy.ts index 5960bfd8dd..f6e4e333b8 100644 --- a/e2e/tests/plugin-copy-code/copy-code.cy.ts +++ b/e2e/tests/plugin-copy-code/copy-code.cy.ts @@ -1,12 +1,19 @@ describe('copy-code', () => { it('have copy code button', () => { - cy.visit('/markdown.html') - .get('.copy-code-button') - .then((el) => { - expect(el.length).to.be.greaterThan(0) + cy.visit('/copy-code/') + .get('.theme-default-content') + .within(() => { + cy.get('.copy-code-button') + .should('have.lengthOf.greaterThan', 0) + .each((el) => { + cy.wrap(el).click() + cy.wrap(el).should('have.class', 'copied') + cy.window() + .then((win) => win.navigator.clipboard.readText()) + .should('match', /const a = 1\r?\nconst b = 2\r?\n/) - cy.wrap(el).click({ multiple: true }) - cy.wrap(el).should('have.class', 'copied') + cy.window().then((win) => win.navigator.clipboard.writeText('')) + }) }) }) }) diff --git a/e2e/tests/plugin-feed/feed.cy.ts b/e2e/tests/plugin-feed/feed.cy.ts index 711f3306b6..f7f7bd1feb 100644 --- a/e2e/tests/plugin-feed/feed.cy.ts +++ b/e2e/tests/plugin-feed/feed.cy.ts @@ -2,76 +2,84 @@ describe('feed', () => { const BASE = Cypress.env('E2E_BASE') it('have atom feed', () => { - cy.request(`${BASE}atom.xml`).then((res) => { - expect(res.body).to.be.a('string') - expect(res.body).to.contain('article excerpt') - }) - cy.request(`${BASE}atom.xsl`).then((res) => { - expect(res.body).to.be.a('string') - expect(res.body).to.contain('article excerpt') + + cy.request(`${BASE}atom.xsl`) + .its('body') + .should('be.a', 'string') + .and('contain', ' { - cy.request(`${BASE}feed.json`).then((res) => { - expect(res.body).to.be.a('object') - expect(res.body).to.have.property( - 'version', - 'https://jsonfeed.org/version/1.1', - ) - expect(JSON.stringify(res.body)).to.contain( - 'article excerpt', - ) - }) + cy.request(`${BASE}feed.json`) + .its('body') + .should('be.a', 'object') + .and((json) => { + expect(JSON.stringify(json)).to.contain( + 'article excerpt', + ) + }) + .and('have.a.property', 'version', 'https://jsonfeed.org/version/1.1') }) it('have rss feed', () => { - cy.request(`${BASE}rss.xml`).then((res) => { - expect(res.body).to.be.a('string') - expect(res.body).to.contain('article excerpt') - }) - cy.request(`${BASE}rss.xsl`).then((res) => { - expect(res.body).to.be.a('string') - expect(res.body).to.contain('article excerpt') + + cy.request(`${BASE}rss.xsl`) + .its('body') + .should('be.a', 'string') + .and('contain', ' { - cy.request(`${BASE}atom.xml`).then((res) => { - expect(res.body).to.contain('Custom feed title') - expect(res.body).to.contain('Custom feed content.') - }) + cy.request(`${BASE}atom.xml`) + .its('body') + .should('be.a', 'string') + .and('contain', 'Custom feed title') + .and('contain', 'Custom feed content.') - cy.request(`${BASE}feed.json`).then((res) => { - const content = JSON.stringify(res.body) + cy.request(`${BASE}feed.json`) + .its('body') + .should('be.a', 'object') + .and((json) => { + const content = JSON.stringify(json) - expect(content).to.contain('Custom feed title') - expect(content).to.contain('Custom feed description') - expect(content).to.contain('Custom feed content.') - }) + expect(content).to.contain('Custom feed title') + expect(content).to.contain('Custom feed description') + expect(content).to.contain('Custom feed content.') + }) - cy.request(`${BASE}rss.xml`).then((res) => { - expect(res.body).to.contain('Custom feed title') - expect(res.body).to.contain('Custom feed description') - expect(res.body).to.contain('Custom feed content.') - }) + cy.request(`${BASE}rss.xml`) + .its('body') + .should('be.a', 'string') + .and('contain', 'Custom feed title') + .and('contain', 'Custom feed description') + .and('contain', 'Custom feed content.') }) it('exclude feed', () => { - cy.request(`${BASE}atom.xml`).then((res) => { - expect(res.body).to.not.contain('Excluded feed page content.') - }) + cy.request(`${BASE}atom.xml`) + .its('body') + .should('not.contain', 'Excluded feed page content.') - cy.request(`${BASE}feed.json`).then((res) => { - const content = JSON.stringify(res.body) + cy.request(`${BASE}feed.json`) + .its('body') + .and((json) => { + const content = JSON.stringify(json) - expect(content).to.not.contain('Excluded feed page content.') - }) + expect(content).to.not.contain('Excluded feed page content.') + }) - cy.request(`${BASE}rss.xml`).then((res) => { - expect(res.body).to.not.contain('Excluded feed page content.') - }) + cy.request(`${BASE}rss.xml`) + .its('body') + .should('not.contain', 'Excluded feed page content.') }) }) diff --git a/e2e/tests/plugin-seo/seo.cy.ts b/e2e/tests/plugin-seo/seo.cy.ts index cd340d3f78..1b6449e0ad 100644 --- a/e2e/tests/plugin-seo/seo.cy.ts +++ b/e2e/tests/plugin-seo/seo.cy.ts @@ -4,69 +4,60 @@ describe('seo', () => { it('have OGP', () => { cy.visit('/seo/') - cy.get('head meta[property="og:url"]').should( - 'have.attr', - 'content', - `https://ecosystem-e2e-test.com${BASE}seo/`, - ) - cy.get('head meta[property="og:site_name"]').should( - 'have.attr', - 'content', - 'VuePress Ecosystem E2E', - ) - cy.get('head meta[property="og:title"]').should( - 'have.attr', - 'content', - 'SEO Demo Page', - ) - cy.get('head meta[property="og:description"]').should( - 'have.attr', - 'content', - 'Here is article excerpt. Content alt Here is main content of article. A B C ', - ) - cy.get('head meta[property="og:type"]').should( - 'have.attr', - 'content', - 'article', - ) - cy.get('head meta[property="og:locale"]').should( - 'have.attr', - 'content', - 'en-US', - ) - cy.get('head meta[property="article:author"]').should( - 'have.attr', - 'content', - 'Mr.Hope', - ) - cy.get('head meta[property="article:tag"]').should( - 'have.attr', - 'content', - 'Demo', - ) - cy.get('head meta[property="article:published_time"]').should( - 'have.attr', - 'content', - '2021-01-01T00:00:00.000Z', - ) + .get('head meta[property="og:url"]') + .should( + 'have.attr', + 'content', + `https://ecosystem-e2e-test.com${BASE}seo/`, + ) + + .get('head meta[property="og:site_name"]') + .should('have.attr', 'content', 'VuePress Ecosystem E2E') + + .get('head meta[property="og:title"]') + .should('have.attr', 'content', 'SEO Demo Page') + + .get('head meta[property="og:description"]') + .should( + 'have.attr', + 'content', + 'Here is article excerpt. Content alt Here is main content of article. A B C ', + ) + + .get('head meta[property="og:type"]') + .should('have.attr', 'content', 'article') + + .get('head meta[property="og:locale"]') + .should('have.attr', 'content', 'en-US') + + .get('head meta[property="article:author"]') + .should('have.attr', 'content', 'Mr.Hope') + + .get('head meta[property="article:tag"]') + .should('have.attr', 'content', 'Demo') + + .get('head meta[property="article:published_time"]') + .should('have.attr', 'content', '2021-01-01T00:00:00.000Z') }) it('have JSONLD', () => { cy.visit('/seo/') - cy.get('head script[type="application/ld+json"]').then((el) => { - const json = JSON.parse(el[0].innerText) + cy.get('head script[type="application/ld+json"]') + .should('have.length', 1) + .each((el) => { + const json = JSON.parse(el[0].innerText) - expect(json['@context']).to.equal('https://schema.org') - expect(json['@type']).to.equal('Article') - expect(json.headline).to.equal('SEO Demo Page') - expect(json.image).to.deep.equal([ - `https://ecosystem-e2e-test.com${BASE}logo.png`, - ]) - expect(json.datePublished).to.equal('2021-01-01T00:00:00.000Z') - expect(json).to.has.property('dateModified') - expect(json.author[0]['@type']).to.equal('Person') - expect(json.author[0].name).to.equal('Mr.Hope') - }) + expect(json['@context']).to.equal('https://schema.org') + expect(json['@type']).to.equal('Article') + expect(json.headline).to.equal('SEO Demo Page') + expect(json.image).to.deep.equal([ + `https://ecosystem-e2e-test.com${BASE}logo.png`, + ]) + expect(json.datePublished).to.equal('2021-01-01T00:00:00.000Z') + expect(json).to.has.property('dateModified') + expect(json.author[0]['@type']).to.equal('Person') + expect(json.author[0].name).to.equal('Mr.Hope') + }) }) }) diff --git a/e2e/tests/theme-default/home.cy.ts b/e2e/tests/theme-default/home.cy.ts index f074991663..f633f4ea0a 100644 --- a/e2e/tests/theme-default/home.cy.ts +++ b/e2e/tests/theme-default/home.cy.ts @@ -2,30 +2,36 @@ describe('homepage', () => { const BASE = Cypress.env('E2E_BASE') it('has hero info', () => { - const title = 'VuePress Ecosystem E2E' - const description = 'VuePress Ecosystem E2E Test Site' - const heroImage = 'https://v2.vuepress.vuejs.org/images/hero.png' - cy.visit('/') - cy.get('.hero img') - .should('have.attr', 'src', heroImage) - .should('have.attr', 'alt', title) + cy.get('.hero').within(() => { + const title = 'VuePress Ecosystem E2E' + const description = 'VuePress Ecosystem E2E Test Site' + const heroImage = 'https://v2.vuepress.vuejs.org/images/hero.png' + + cy.get('img') + .should('have.attr', 'src', heroImage) + .should('have.attr', 'alt', title) - cy.get('#main-title').should('have.text', title) + cy.get('#main-title').should('have.text', title) - cy.get('.hero .description').should('have.text', description) + cy.get('.description').should('have.text', description) - cy.get('.actions .action-button') - .should('have.length', 2) - .each((el, index) => { - cy.wrap(el) - .should('have.attr', 'href', `${BASE}action${index + 1}.html`) - .should('have.attr', 'aria-label', `Action${index + 1}`) - .contains(`Action${index + 1}`) - }) + cy.get('.action-button') + .should('have.length', 2) + .each((el, index) => { + cy.wrap(el) + .should('have.attr', 'href', `${BASE}action${index + 1}.html`) + .should('have.attr', 'aria-label', `Action${index + 1}`) + .contains(`Action${index + 1}`) + }) + }) + }) + + it('has feature', () => { + cy.visit('/') - cy.get('.features .feature').then((el) => { + cy.get('.feature').then((el) => { cy.wrap(el) .should('have.length', 3) .each((el, index) => { diff --git a/e2e/tests/theme-default/navbar.cy.ts b/e2e/tests/theme-default/navbar.cy.ts index b4b06a8568..4c97c94ed5 100644 --- a/e2e/tests/theme-default/navbar.cy.ts +++ b/e2e/tests/theme-default/navbar.cy.ts @@ -1,9 +1,7 @@ it('has navbar', () => { cy.visit('/') - cy.get('.theme-default-content').then((el) => { - cy.wrap(el) - .get('.navbar .navbar-item') - .should('contain', 'Home') - .should('contain', 'Dropdown') - }) + + cy.get('.navbar .navbar-item') + .should('contain', 'Home') + .should('contain', 'Dropdown') }) diff --git a/e2e/tests/theme-default/sidebar.cy.ts b/e2e/tests/theme-default/sidebar.cy.ts index a11d17e98b..176812c021 100644 --- a/e2e/tests/theme-default/sidebar.cy.ts +++ b/e2e/tests/theme-default/sidebar.cy.ts @@ -1,39 +1,30 @@ describe('has heading sidebar', () => { it('frontmatter', () => { cy.visit('/sidebar/auto.html') - cy.get('.theme-default-content').then((el) => { - cy.wrap(el) - .get('a.sidebar-item') - .should('contain', 'Sidebar Heading 1') - .should('contain', 'Sidebar Heading 2') - }) + + cy.get('a.sidebar-item') + .should('contain', 'Sidebar Heading 1') + .should('contain', 'Sidebar Heading 2') }) it('config', () => { cy.visit('/sidebar/heading/1.html') - cy.get('.theme-default-content').then((el) => { - cy.wrap(el) - .get('h1') + cy.get('.theme-default-content h1') + .invoke('text') + .should('be.not.empty') + .then((text) => { + cy.get('.sidebar-heading') + .invoke('text') + .should('contain', text.replace('#', '').trim()) + }) + + cy.get('.theme-default-content h2').each((header) => { + cy.wrap(header) .invoke('text') .should('be.not.empty') - .then((text) => { - cy.get('.sidebar-heading') - .invoke('text') - .should('contain', text.replace('#', '').trim()) - }) - - cy.wrap(el) - .get('h2') - .each((header) => { - cy.wrap(header) - .invoke('text') - .should('be.not.empty') - .then((headerText) => { - cy.get('a.sidebar-item').contains( - headerText.replace('#', '').trim(), - ) - }) + .then((headerText) => { + cy.get('a.sidebar-item').contains(headerText.replace('#', '').trim()) }) }) }) @@ -41,10 +32,8 @@ describe('has heading sidebar', () => { it('has configured sidebar', () => { cy.visit('/sidebar/config/1.html') - cy.get('.theme-default-content').then((el) => { - cy.wrap(el) - .get('a.sidebar-item') - .should('contain', 'sidebar 1') - .should('contain', 'sidebar 2') - }) + + cy.get('a.sidebar-item') + .should('contain', 'sidebar 1') + .should('contain', 'sidebar 2') }) From fb96225c42910c5dcf20756974f0cdd680a8c876 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 2 Feb 2024 14:28:19 +0800 Subject: [PATCH 4/4] ci: run e2e on all branch --- .github/workflows/e2e.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9ee9665327..f68cfbc51c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -3,7 +3,6 @@ name: e2e on: push: branches: - - main pull_request: branches: - main