aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-09-09 20:07:17 +0800
committerGitHub <[email protected]>2022-09-09 20:07:17 +0800
commit0c6e9b16548614dc0ce91296e3885c9e421e4e99 (patch)
tree49aa500525d26a8ac962fca4a7b026395cf694be
parent83b61429fa710903e4a82fe655a6c196deb16fbd (diff)
downloadfaker-0c6e9b16548614dc0ce91296e3885c9e421e4e99.tar.xz
faker-0c6e9b16548614dc0ce91296e3885c9e421e4e99.zip
test: e2e tests (#1362)
-rw-r--r--.github/workflows/ci.yml6
-rw-r--r--cypress/e2e/api.cy.ts43
-rw-r--r--cypress/e2e/guide.cy.ts13
-rw-r--r--cypress/e2e/smoke.cy.ts26
-rw-r--r--cypress/tsconfig.json7
-rw-r--r--tsconfig.json3
6 files changed, 67 insertions, 31 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a1691afe..83f2ff6a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -67,14 +67,16 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
- cache: 'pnpm'
- name: Install deps
run: pnpm install
- - name: Run E2E
+ - name: Build docs
run: pnpm run docs:build:ci
+ - name: Run e2e
+ run: pnpm run docs:test:e2e:run
+
lint:
runs-on: ubuntu-latest
name: 'Lint: node-18, ubuntu-latest'
diff --git a/cypress/e2e/api.cy.ts b/cypress/e2e/api.cy.ts
new file mode 100644
index 00000000..ec21d3d3
--- /dev/null
+++ b/cypress/e2e/api.cy.ts
@@ -0,0 +1,43 @@
+describe('API Test', () => {
+ it('navigates to the api index search', () => {
+ // given
+ cy.visit('/');
+
+ // when
+ cy.get('a').contains('API').click();
+
+ // then
+ cy.url().should('include', '/api/');
+ cy.contains('API Reference');
+ });
+
+ describe('API Reference', () => {
+ beforeEach(() => {
+ // given
+ cy.visit('/api/');
+ });
+
+ it('should at least list more than 7 modules', () => {
+ cy.get('.api-group').should('have.length.above', 7);
+ });
+
+ it('should include at least 1 element in each module', () => {
+ cy.get('.api-group').each(($el) => {
+ cy.wrap($el).get('li a[href]').should('have.length.above', 0);
+ });
+ });
+
+ it('should not have dead links', () => {
+ cy.get('.api-group li').each(($el) => {
+ const text = $el.find('a').text();
+ const link = $el.find('a').attr('href');
+
+ cy.visit(`/api/${link}`);
+
+ cy.get('h2').should('include.text', text);
+ cy.get('h1').should('not.include.text', 'PAGE NOT FOUND');
+ cy.go('back');
+ });
+ });
+ });
+});
diff --git a/cypress/e2e/guide.cy.ts b/cypress/e2e/guide.cy.ts
new file mode 100644
index 00000000..6186f938
--- /dev/null
+++ b/cypress/e2e/guide.cy.ts
@@ -0,0 +1,13 @@
+describe('Guide Test', () => {
+ it('navigates to the getting started section', () => {
+ // given
+ cy.visit('/');
+
+ // when
+ cy.get('a').contains('Get Started').click();
+
+ // then
+ cy.url().should('include', '/guide/');
+ cy.contains('Getting Started');
+ });
+});
diff --git a/cypress/e2e/smoke.cy.ts b/cypress/e2e/smoke.cy.ts
deleted file mode 100644
index eb3cf1fb..00000000
--- a/cypress/e2e/smoke.cy.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-describe('Smoke Test', () => {
- beforeEach(() => {
- cy.visit('/guide/');
- cy.get('a[href="/api/animal.html"]').as('firstSectionLink');
- });
-
- it('compiles the guide page', () => {
- cy.contains('Getting Started');
- });
-
- it('renders this last code example in the code', () => {
- // Click on any section in the sidebar
- cy.get('@firstSectionLink')
- .click()
- // Make sure the number of code examples is the same between reloads
- .get('.container pre code')
- .then(($codeBlocks) => {
- // Trigger a reload
- cy.reload()
- // Give the runtime a chance to update/fail
- .wait(500)
- .get('.container pre code')
- .should('have.length', $codeBlocks.length);
- });
- });
-});
diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json
index 5e8cb532..0446ab75 100644
--- a/cypress/tsconfig.json
+++ b/cypress/tsconfig.json
@@ -1,8 +1,11 @@
{
"compilerOptions": {
"target": "ES5",
- "lib": ["ES5", "DOM"],
- "types": ["cypress"]
+ "lib": ["ES2015", "DOM"],
+ "types": ["cypress"],
+ "esModuleInterop": true,
+ "noEmit": true,
+ "resolveJsonModule": true
},
"include": ["**/*.ts"]
}
diff --git a/tsconfig.json b/tsconfig.json
index 1944ff18..f96902eb 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -15,7 +15,8 @@
// "noImplicitAny": true,
// "noImplicitThis": true,
"useUnknownInCatchVariables": true,
- "stripInternal": true
+ "stripInternal": true,
+ "baseUrl": "."
},
"include": ["src/**/*"],
"exclude": ["node_modules"]