Skip to content

Commit b014e02

Browse files
committed
test: provide an end to end test for the plugin
1 parent 77a95cb commit b014e02

File tree

9 files changed

+32520
-7761
lines changed

9 files changed

+32520
-7761
lines changed

.github/workflows/e2e.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: e2e test
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
jobs:
8+
test:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest]
13+
node: [16]
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v2
17+
- name: use node ${{ matrix.node }}
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node }}
21+
- name: install dependencies
22+
uses: cypress-io/github-action@v2
23+
with:
24+
runTests: false
25+
- name: print cypress info
26+
run: npx cypress info
27+
- name: test on chrome
28+
uses: cypress-io/github-action@v2
29+
with:
30+
working-directory: e2e
31+
browser: chrome
32+
record: true
33+
build: true
34+
install: false
35+
start: npm run start:gatsby
36+
wait-on: http://localhost:8000
37+
env:
38+
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
39+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
40+
GATSBY_NOTION_TOKEN: ${{ secrets.GATSBY_NOTION_TOKEN }}
41+
GATSBY_NOTION_DATABASES: ${{ secrets.GATSBY_NOTION_DATABASES }}
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
DEBUG: '@cypress/github-action'

e2e/.presetterrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"preset": "presetter-preset-strict",
3+
"config": {
4+
"gitignore": ["/.cache", "/public", "/screenshots", "/types/~*", "/videos"],
5+
"tsconfig": {
6+
"compilerOptions": {
7+
"lib": ["DOM"],
8+
"types": ["cypress"]
9+
}
10+
}
11+
},
12+
"variable": {
13+
"source": "src",
14+
"output": "public"
15+
},
16+
"ignores": [".babelrc.json"]
17+
}

e2e/cypress.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"downloadsFolder": "downloads",
3+
"fixturesFolder": "fixtures",
4+
"integrationFolder": "integration",
5+
"pluginsFile": false,
6+
"screenshotsFolder": "screenshots",
7+
"supportFile": false,
8+
"testFiles": "**/*.ts",
9+
"videosFolder": "videos"
10+
}

e2e/gatsby-config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* *** MIT LICENSE ***
3+
* -------------------------------------------------------------------------
4+
* This code may be modified and distributed under the MIT license.
5+
* See the LICENSE file for details.
6+
* -------------------------------------------------------------------------
7+
*
8+
* @summary Specify the configuration for Gatsby.
9+
*
10+
* See https://www.gatsbyjs.org/docs/gatsby-config
11+
* for detailed usage
12+
*
13+
* @author Alvis HT Tang <alvis@hilbert.space>
14+
* @license MIT
15+
* @copyright Copyright (c) 2021 - All Rights Reserved.
16+
* -------------------------------------------------------------------------
17+
*/
18+
19+
/* istanbul ignore file */
20+
21+
import type { GatsbyConfig } from 'gatsby';
22+
23+
export const plugins: GatsbyConfig['plugins'] = [
24+
{
25+
resolve: 'gatsby-plugin-graphql-codegen',
26+
options: {
27+
fileName: './types/~graphql.ts',
28+
documentPaths: ['./src/**/*.{ts,tsx}'],
29+
},
30+
},
31+
{
32+
resolve: 'gatsby-source-notion',
33+
options: {
34+
previewCallRate: 0.5,
35+
},
36+
},
37+
];
38+
39+
export default {
40+
plugins,
41+
};

e2e/integration/records.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* *** MIT LICENSE ***
3+
* -------------------------------------------------------------------------
4+
* This code may be modified and distributed under the MIT license.
5+
* See the LICENSE file for details.
6+
* -------------------------------------------------------------------------
7+
*
8+
* @summary Tests on the ability read data from notion
9+
*
10+
* @author Alvis HT Tang <alvis@hilbert.space>
11+
* @license MIT
12+
* @copyright Copyright (c) 2021 - All Rights Reserved.
13+
* -------------------------------------------------------------------------
14+
*/
15+
16+
import { after } from 'cypress/types/lodash';
17+
18+
describe('capture databases and pages from notion', () => {
19+
beforeEach(() => {
20+
cy.visit('http://localhost:8000');
21+
});
22+
23+
afterEach(() => {
24+
cy.screenshot();
25+
});
26+
27+
it('print database and page titles', () => {
28+
cy.get('#databases li').should('have.length.gt', 0);
29+
cy.get('#pages li').should('have.length.gt', 0);
30+
});
31+
});

e2e/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "e2e",
3+
"version": "0.0.0",
4+
"description": "end to end test for the plugin",
5+
"private": true,
6+
"scripts": {
7+
"build": "ts-node-cwd --transpile-only -- ../node_modules/.bin/gatsby build --verbose",
8+
"prepare": "presetter bootstrap",
9+
"start": "start-server-and-test start:gatsby 8000 \"cypress open\"",
10+
"start:gatsby": "cross-env CYPRESS_SUPPORT=y ts-node-cwd --transpile-only -- ../node_modules/.bin/gatsby develop --port 8000 --verbose",
11+
"test": "start-server-and-test start:gatsby 8000 \"cypress run\""
12+
},
13+
"devDependencies": {
14+
"cypress": "^8.7.0",
15+
"gatsby-plugin-graphql-codegen": "^3.0.0",
16+
"presetter": "^3.0.0",
17+
"presetter-preset-strict": "^3.0.0",
18+
"start-server-and-test": "^1.0.0"
19+
},
20+
"dependencies": {
21+
"gatsby": "^3.0.0-next.0"
22+
}
23+
}

e2e/src/pages/index.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* *** MIT LICENSE ***
3+
* -------------------------------------------------------------------------
4+
* This code may be modified and distributed under the MIT license.
5+
* See the LICENSE file for details.
6+
* -------------------------------------------------------------------------
7+
*
8+
* @summary Test page
9+
*
10+
* @author Alvis HT Tang <alvis@hilbert.space>
11+
* @license MIT
12+
* @copyright Copyright (c) 2021 - All Rights Reserved.
13+
* -------------------------------------------------------------------------
14+
*/
15+
16+
import { graphql } from 'gatsby';
17+
import React from 'react';
18+
19+
import type { PageProps } from 'gatsby';
20+
import type { FC } from 'react';
21+
22+
import type { IndexPageQuery } from '~graphql';
23+
24+
// page query
25+
export const query = graphql`
26+
query IndexPage {
27+
allNotionDatabase {
28+
nodes {
29+
ref
30+
title
31+
}
32+
}
33+
allNotionPage {
34+
nodes {
35+
ref
36+
title
37+
}
38+
}
39+
}
40+
`;
41+
42+
/**
43+
* the test page
44+
* @inheritdoc
45+
* @returns a component holding the test page
46+
*/
47+
const Test: FC<PageProps<IndexPageQuery>> = ({ data }) => (
48+
<>
49+
<section id="databases">
50+
<h1>Databases</h1>
51+
<ul>
52+
{data.allNotionDatabase.nodes.map(({ ref, title }) => (
53+
<li key={ref}>{title}</li>
54+
))}
55+
</ul>
56+
</section>
57+
<section id="pages">
58+
<h1>Pages</h1>
59+
<ul>
60+
{data.allNotionPage.nodes.map(({ ref, title }) => (
61+
<li key={ref}>{title}</li>
62+
))}
63+
</ul>
64+
</section>
65+
</>
66+
);
67+
68+
/**
69+
* the test page
70+
* @inheritdoc
71+
* @returns a component holding the test page
72+
*/
73+
// const Test: FC<PageProps> = ({ data }) => <div>hi!</div>;
74+
75+
export default Test;
76+

0 commit comments

Comments
 (0)