Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 8a488b5

Browse files
authored
test: add e2e tests (#40)
* chore: switch from npmignore to including file in package.json * chore: add minimal example site to repo and start in ci * fix(ci): remove serve from scripts Prevents the CI from running indefinitely. This will be reintroduced when setting up cypress" * chore: set up cypress and run in ci
1 parent 5bd1fdd commit 8a488b5

File tree

11 files changed

+769
-68
lines changed

11 files changed

+769
-68
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignoring examples because of eslint conflicts with the nested package
2+
examples

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ jobs:
1515
run: yarn install
1616
- name: Lint
1717
run: yarn lint
18+
- name: E2E
19+
env:
20+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
21+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22+
AWS_REGION: ${{ secrets.AWS_REGION }}
23+
run: yarn e2e

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ node_modules
33

44
# generated source plugin
55
gatsby-node.js
6+
robinmetral-gatsby-source-s3-0.0.0-semantically-released.tgz
7+
8+
# example site
9+
.env
10+
.cache
11+
public
12+
examples/gatsby-starter-source-s3/yarn.lock
13+
14+
# cypress
15+
tests/screenshots

.npmignore

Lines changed: 0 additions & 11 deletions
This file was deleted.

cypress.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"integrationFolder": "tests",
3+
"screenshotsFolder": "tests/screenshots",
4+
"fixturesFolder": false,
5+
"supportFile": false,
6+
"video": false,
7+
"pluginsFile": false
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require("dotenv").config();
2+
3+
module.exports = {
4+
siteMetadata: {
5+
title: `gatsby-starter-source-s3`
6+
},
7+
plugins: [
8+
{
9+
resolve: `@robinmetral/gatsby-source-s3`,
10+
options: {
11+
aws: {
12+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
13+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
14+
region: process.env.AWS_REGION
15+
},
16+
buckets: ["gatsby-source-s3-example", "gatsby-source-s3-example-2"]
17+
}
18+
},
19+
// the sharp transformer and plugin are required to process images
20+
`gatsby-transformer-sharp`,
21+
`gatsby-plugin-sharp`
22+
]
23+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "gatsby-starter-source-s3",
4+
"description": "A simple starter to get started with @robinmetral/gatsby-source-s3",
5+
"version": "1.0.0",
6+
"license": "MIT",
7+
"author": "Robin Métral <[email protected]>",
8+
"dependencies": {
9+
"@robinmetral/gatsby-source-s3": "file:../../robinmetral-gatsby-source-s3-0.0.0-semantically-released.tgz",
10+
"gatsby": "^2.19.7",
11+
"gatsby-image": "^2.2.39",
12+
"gatsby-plugin-sharp": "^2.4.3",
13+
"gatsby-transformer-sharp": "^2.3.13",
14+
"react": "^16.12.0",
15+
"react-dom": "^16.12.0"
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from "react";
2+
import { graphql } from "gatsby";
3+
import Img from "gatsby-image";
4+
5+
const IndexPage = ({ data }) => (
6+
<>
7+
<h1>{data.site.siteMetadata.title}</h1>
8+
{data.allS3Object.nodes.map(image => (
9+
<Img fixed={image.localFile.childImageSharp.fixed} alt={image.Key} />
10+
))}
11+
</>
12+
);
13+
14+
export const IMAGES_QUERY = graphql`
15+
query {
16+
site {
17+
siteMetadata {
18+
title
19+
}
20+
}
21+
allS3Object {
22+
nodes {
23+
Key
24+
localFile {
25+
childImageSharp {
26+
fixed(width: 256) {
27+
...GatsbyImageSharpFixed
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
`;
35+
36+
export default IndexPage;

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,33 @@
1111
"gatsby-plugin",
1212
"gatsby-source-plugin"
1313
],
14+
"files": [
15+
"gatsby-node.js"
16+
],
1417
"devDependencies": {
1518
"@commitlint/cli": "^8.3.5",
1619
"@commitlint/config-conventional": "^8.3.4",
1720
"@types/node": "^14.0.1",
1821
"@typescript-eslint/eslint-plugin": "^2.33.0",
1922
"@typescript-eslint/parser": "^2.33.0",
23+
"cypress": "^4.5.0",
2024
"eslint": "^7.0.0",
2125
"eslint-config-prettier": "^6.11.0",
2226
"eslint-plugin-prettier": "^3.1.3",
2327
"gatsby": "^2.21.33",
2428
"husky": "^4.2.5",
2529
"prettier": "^1.19.1",
2630
"semantic-release": "^17.0.7",
31+
"start-server-and-test": "^1.11.0",
2732
"typescript": "^3.9.2"
2833
},
2934
"scripts": {
3035
"build": "tsc",
31-
"lint": "eslint '*/**/*.{ts,tsx}'"
36+
"lint": "eslint '*/**/*.{ts,tsx}'",
37+
"prestart": "yarn build && npm pack && (cd examples/gatsby-starter-source-s3 && yarn install && yarn add file:../../robinmetral-gatsby-source-s3-0.0.0-semantically-released.tgz)",
38+
"start": "(cd examples/gatsby-starter-source-s3 && gatsby build && gatsby serve)",
39+
"test": "cypress run",
40+
"e2e": "start-server-and-test http://localhost:9000"
3241
},
3342
"dependencies": {
3443
"aws-sdk": "^2.678.0",

tests/main.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe("e2e", () => {
2+
it("should source images from S3", () => {
3+
cy.visit("http://localhost:9000");
4+
5+
cy.get("img").should("exist");
6+
});
7+
});

0 commit comments

Comments
 (0)