Skip to content

Commit 4ab316f

Browse files
authored
Added telemetry and fixed jest (#9)
* Added telemetry and fixed hyperlink bug * Fixed jest, added a pr template, and added github workflows * Delete tests directory * split test:jest script * Removed config from dockerfile
1 parent 3e6bd2a commit 4ab316f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2107
-2072
lines changed

.dockerignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
.nyc_output
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
*.code-workspace
23+
24+
# debug
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*
28+
29+
# local env files
30+
.env.local
31+
.env.development.local
32+
.env.test.local
33+
.env.production.local
34+
35+
# vercel
36+
.vercel
37+
38+
#public ignores
39+
/public/*.js
40+
/public/*.js.map
41+
42+
package-lock.json
43+
44+
/docs
45+
/stacks
46+
47+
#specifically dockerignore
48+
**/__tests__
49+
.vscode
50+
.github
51+
cypress
52+
cypress.json
53+
jest.config.js
54+
jest.setup.js
55+
LICENSE
56+
OWNERSHIP
57+
README.md

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"plugin:cypress/recommended",
2020
"eslint:recommended",
2121
"plugin:@typescript-eslint/recommended",
22-
"plugin:react/recommended"
22+
"plugin:react/recommended",
23+
"next"
2324
],
2425
"parserOptions": {
2526
"project": "./tsconfig.json",

.github/PULL_REQUEST_TEMPLATE.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**What does this PR do / why we need it**:
2+
3+
**Which issue(s) this PR fixes**:
4+
5+
Fixes #?
6+
7+
**PR acceptance criteria**:
8+
9+
- [ ] Unit Tests
10+
- [ ] E2E Tests
11+
- [ ] Documentation
12+
13+
**How to test changes / Special notes to the reviewer**:

.github/workflows/Cypress.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name: Cypress
22

3-
# Triggers the workflow on push or pull request events but only for the main branch
43
on:
5-
push:
4+
push:
65
branches: [main]
76
pull_request:
87
branches: [main]
98

109
jobs:
1110
cypress-run:
11+
name: Cypress
12+
1213
runs-on: ubuntu-latest
1314
steps:
1415
- name: Checkout

.github/workflows/Docker.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
docker-build:
11+
name: Docker
12+
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Check if docker image build is working
18+
run: docker build -f Dockerfile .
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
name: Lint
1+
name: Run Scripts
22

3-
# Triggers the workflow on push or pull request events but only for the main branch
43
on:
5-
push:
6-
branches: [main]
74
pull_request:
85
branches: [main]
96

107
jobs:
11-
run-linters:
12-
name: Run linters
8+
jest-run:
9+
name: Run Scripts
1310
runs-on: ubuntu-latest
1411

1512
steps:
@@ -22,7 +19,10 @@ jobs:
2219
node-version: 14
2320

2421
- name: Install Node.js dependencies
25-
run: yarn install --ignore-optional
22+
run: yarn install
2623

24+
- name: Run Jest
25+
run: yarn test:jest
26+
2727
- name: Run Prettier
2828
run: yarn lint

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# testing
99
/coverage
1010
.nyc_output
11+
/cypress
1112

1213
# next.js
1314
/.next/

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"arrowParens": "always",
33
"printWidth": 100,
44
"singleQuote": true,
5-
"trailingComma": "none"
5+
"trailingComma": "all"
66
}

Dockerfile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rebuild the source code only when needed
2+
FROM registry.access.redhat.com/ubi8/nodejs-14-minimal AS builder
3+
ARG DEVFILE_VIEWER_ROOT
4+
ARG DEVFILE_COMMUNITY_HOST
5+
USER root
6+
WORKDIR /app
7+
RUN npm install -g yarn
8+
COPY . .
9+
RUN $(npm get prefix)/bin/yarn install --frozen-lockfile --ignore-optional
10+
RUN $(npm get prefix)/bin/yarn build
11+
RUN $(npm get prefix)/bin/yarn install --production --ignore-scripts --prefer-offline --ignore-optional
12+
13+
# Production image, copy all the files and run next
14+
FROM registry.access.redhat.com/ubi8/nodejs-14-minimal AS runner
15+
USER root
16+
WORKDIR /app
17+
RUN microdnf install shadow-utils
18+
19+
ENV NODE_ENV production
20+
21+
RUN groupadd -g 1001 nodejs
22+
RUN useradd nextjs -u 1001
23+
24+
COPY --from=builder /app/next.config.js ./
25+
COPY --from=builder /app/public ./public
26+
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
27+
COPY --from=builder /app/node_modules ./node_modules
28+
COPY --from=builder /app/package.json ./package.json
29+
COPY --from=builder --chown=nextjs:nodejs /app/webpage_info ./webpage_info
30+
31+
USER nextjs
32+
33+
EXPOSE 3000
34+
35+
CMD ["npm", "start"]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Start a production server with `yarn start` or `npm run start`.
1414

1515
## Adding or updating information static webpage information
1616

17-
The folder `webpage_info` contains the static webpage files. If the layout text or the main page text need to be modified they are in the corresponding json file. The json file has been added for simplicity and the changes located in them will be reflected in the next build of the application. They _cannot_ be dynamically updated!
17+
The directory `webpage_info` contains the static webpage files. If the layout text or the main page text need to be modified they are in the corresponding json file. The json file has been added for simplicity and the changes located in them will be reflected in the next build of the application. They _cannot_ be dynamically updated!
1818

1919
### `/getting-started`
2020

21-
The folder `getting-started` represents the navigation in the Getting Started section of the landing page. The folder name after the first letter will be displayed as is on the navigation bar. If you want the navigation elements to be ordered add a number before the folder name. Any character before the first letter will be used for sorting purposes and will be removed before displaying. Currently, the navigation bar only supports using the folder as the navigation group and the md or adoc file(s) as the navigation elements. This will be changed in future releases.
21+
The directory `getting-started` represents the navigation in the Getting Started section of the landing page. The directory name after the first letter will be displayed as is on the navigation bar. If you want the navigation elements to be ordered add a number before the directory name. Any character before the first letter will be used for sorting purposes and will be removed before displaying. Currently, the navigation bar only supports using the directory as the navigation group and the md or adoc file(s) as the navigation elements. This will be changed in future releases. Note: The `+` symbol cannot be used in the name for either a file or directory in the `getting-started` directory.
2222

2323
## CI/CD
2424

__tests__/mocks/fileMock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

__tests__/mocks/styleMock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

__tests__/plugins/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
// eslint-disable-next-line spaced-comment
3+
/// <reference types="cypress" />
4+
5+
export {};
6+
7+
module.exports = (
8+
on: Cypress.PluginEvents,
9+
config: Cypress.PluginConfigOptions,
10+
): Cypress.PluginConfigOptions => {
11+
require('@cypress/code-coverage/task')(on, config);
12+
return config;
13+
};
File renamed without changes.
File renamed without changes.

checkConfigTypes.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Ignore parserOptions.project warning.
22
This file is only run pre-build */
33
// @ts-check
4-
const fs = require(`fs`);
5-
const path = require(`path`);
4+
const fs = require('fs');
5+
const path = require('path');
66

77
const configFileString = 'The config file "./webpage_info/layout-text.json"';
88

@@ -66,22 +66,22 @@ function checkArrayPropertyTypes(arr, arrName) {
6666
arr.forEach((elem) => {
6767
if (!elem.name) {
6868
throw TypeError(
69-
`${configFileString} "${arrName}" array has an element with no "name" property`
69+
`${configFileString} "${arrName}" array has an element with no "name" property`,
7070
);
7171
}
7272
if (!elem.link) {
7373
throw TypeError(
74-
`${configFileString} "${arrName}" array has an element with no "link" property`
74+
`${configFileString} "${arrName}" array has an element with no "link" property`,
7575
);
7676
}
7777
if (typeof elem.name !== 'string') {
7878
throw TypeError(
79-
`${configFileString} "${arrName}" array has an element with "name" property not as a string`
79+
`${configFileString} "${arrName}" array has an element with "name" property not as a string`,
8080
);
8181
}
8282
if (typeof elem.link !== 'string') {
8383
throw TypeError(
84-
`${configFileString} "${arrName}" array has an element with "link" property not as a string`
84+
`${configFileString} "${arrName}" array has an element with "link" property not as a string`,
8585
);
8686
}
8787
});

cypress.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"baseUrl": "http://localhost:3000/",
3-
"fixturesFolder": "tests/fixtures",
4-
"integrationFolder": "tests/integration",
5-
"supportFile": "tests/support/index.ts",
3+
"fixturesFolder": "__tests__/fixtures",
4+
"integrationFolder": "__tests__/integration",
5+
"pluginsFile": "__tests__/plugins/index.ts",
6+
"supportFile": "__tests__/support/index.ts",
67
"video": false
78
}

jest.config.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
collectCoverageFrom: ['**/*.{js,jsx,ts,tsx}', '!**/*.d.ts', '!**/node_modules/**'],
3+
testMatch: ['**/__tests__/**/*.{js,ts}?(x)', '**/*.test.{js,ts}?(x)'],
4+
moduleNameMapper: {
5+
/* Handle CSS imports (with CSS modules)
6+
https://jestjs.io/docs/webpack#mocking-css-modules */
7+
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
8+
9+
// Handle CSS imports (without CSS modules)
10+
'^.+\\.(css|sass|scss)$': '<rootDir>/__tests__/mocks/styleMock.js',
11+
12+
/* Handle image imports
13+
https://jestjs.io/docs/webpack#handling-static-assets */
14+
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': '<rootDir>/__tests__/mocks/fileMock.js',
15+
16+
/* Handle compilerOptions.paths in ./tsconfig */
17+
'@src(.*)': '<rootDir>/src/$1',
18+
'@public(.*)': '<rootDir>/public/$1',
19+
'@config(.*)': '<rootDir>/config/$1',
20+
'@info(.*)': '<rootDir>/webpage_info/$1',
21+
},
22+
modulePaths: ['<rootDir>'],
23+
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/', '<rootDir>/__tests__'],
24+
testEnvironment: 'jsdom',
25+
transform: {
26+
/* Use babel-jest to transpile tests with the next/babel preset
27+
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
28+
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
29+
},
30+
transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss)$'],
31+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
32+
};

jest.setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/extend-expect';

next.config.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const withPlugins = require('next-compose-plugins');
44
const withPWA = require('next-pwa');
55
const withImages = require('next-images');
66
const withBundleAnalyzer = require('@next/bundle-analyzer')({
7-
enabled: process.env.ANALYZE === 'true'
7+
enabled: process.env.ANALYZE === 'true',
88
});
99
const withTM = require('next-transpile-modules')([
1010
'@patternfly/react-core',
11-
'@patternfly/react-styles'
11+
'@patternfly/react-styles',
1212
]);
1313

1414
module.exports = withPlugins([withTM, withImages, withBundleAnalyzer, withPWA], {
@@ -19,16 +19,25 @@ module.exports = withPlugins([withTM, withImages, withBundleAnalyzer, withPWA],
1919
loader: 'ts-loader',
2020
options: {
2121
getCustomTransformers: (program) => ({
22-
before: [typescriptIsTransformer(program)]
23-
})
24-
}
22+
before: [typescriptIsTransformer(program)],
23+
}),
24+
},
2525
});
2626
return config;
2727
},
2828
basePath: process.env.LANDING_PAGE_ROOT ? process.env.LANDING_PAGE_ROOT : '',
2929
pwa: {
30-
disable: process.env.NODE_ENV === 'development',
30+
/**
31+
* Uncomment the line below if the pwa issue is fixed.
32+
* The issue is because of nextjs 12 and next-pwa needs to be updated
33+
*/
34+
// disable: process.env.NODE_ENV === 'development',
35+
disable: true, //
3136
register: true,
32-
dest: 'public'
33-
}
37+
dest: 'public',
38+
},
39+
publicRuntimeConfig: {
40+
analyticsWriteKey: process.env.ANALYTICS_WRITE_KEY || '',
41+
segmentUserId: 'landing-page',
42+
},
3443
});

0 commit comments

Comments
 (0)