-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add config env test + some github workflows
- Loading branch information
Tien Nam Dao
committed
Feb 21, 2023
1 parent
1fd7998
commit e8bf9ff
Showing
12 changed files
with
1,862 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
NEXT_PUBLIC_BLOCK_INTERVAL=5000 | ||
NEXT_PUBLIC_TRANSACTION_INTERVAL=5000 | ||
NEXT_PUBLIC_CHART_INTERVAL=600000 | ||
NEXT_PUBLIC_DATE_FORMAT_VI='DD/MM/YYYY' | ||
NEXT_PUBLIC_DATE_FROMAT_OTHER='MM/DD/YYYY' | ||
NEXT_PUBLIC_ITEM_SHOW_HOME_PAGE=7 | ||
NEXT_PUBLIC_PAGE_OFFSET=10 | ||
NEXT_PUBLIC_MAXIMUM_FRACTION_DIGITS=4 | ||
NEXT_PUBLIC_NATIVE_TOKEN='asa' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
node: [16] | ||
|
||
name: Lint | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.x | ||
registry-url: 'https://npm.pkg.github.com' | ||
scope: '@astraprotocol' | ||
token: ${{ secrets.PAT_ASTRAPROTOCOL }} | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- uses: actions/cache@v2 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Setup npm token | ||
run: npm config set '//npm.pkg.github.com/:_authToken' "${{secrets.PAT_ASTRAPROTOCOL}}" | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Run lint | ||
run: yarn lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: 'Lint PR Title' | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
|
||
jobs: | ||
main: | ||
name: Validate PR title | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: amannn/action-semantic-pull-request@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- feat/add-config-test | ||
- dev | ||
- main | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
node: [16] | ||
|
||
name: Unit tests (Jest) | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- uses: actions/cache@v2 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
node_modules/ | ||
.next/ | ||
.DS_STORE | ||
.env | ||
.env.* | ||
package-lock.json | ||
yarn-error.log | ||
.sentryclirc |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
describe('check config', () => { | ||
it('Check not empty any config define in next.config.js', () => { | ||
expect(process.env.NEXT_PUBLIC_BLOCK_INTERVAL).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_TRANSACTION_INTERVAL).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_CHART_INTERVAL).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_DATE_FORMAT_VI).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_DATE_FROMAT_OTHER).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_ITEM_SHOW_HOME_PAGE).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_PAGE_OFFSET).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_MAXIMUM_FRACTION_DIGITS).toBeDefined() | ||
expect(process.env.NEXT_PUBLIC_NATIVE_TOKEN).toBeDefined() | ||
}) | ||
it('Check env number is right', () => { | ||
expect(Number(process.env.NEXT_PUBLIC_BLOCK_INTERVAL)).toBeGreaterThanOrEqual(0) | ||
expect(Number(process.env.NEXT_PUBLIC_TRANSACTION_INTERVAL)).toBeGreaterThanOrEqual(0) | ||
expect(Number(process.env.NEXT_PUBLIC_CHART_INTERVAL)).toBeGreaterThanOrEqual(0) | ||
expect(Number(process.env.NEXT_PUBLIC_ITEM_SHOW_HOME_PAGE)).toBeGreaterThanOrEqual(0) | ||
expect(Number(process.env.NEXT_PUBLIC_PAGE_OFFSET)).toBeGreaterThanOrEqual(0) | ||
expect(Number(process.env.NEXT_PUBLIC_MAXIMUM_FRACTION_DIGITS)).toBeGreaterThanOrEqual(0) | ||
}) | ||
it('Check native token is right', () => { | ||
expect(process.env.NEXT_PUBLIC_NATIVE_TOKEN).toBe('asa') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const nextJest = require('next/jest') | ||
|
||
// Providing the path to your Next.js app which will enable loading next.config.js and .env files | ||
const createJestConfig = nextJest({ dir: './' }) | ||
|
||
// Any custom config you want to pass to Jest | ||
const customJestConfig = { | ||
// testPathIgnorePatterns: ['<rootDir>/cypress/', '<rootDir>/src/config/__tests__/', '<rootDir>/packages'], | ||
|
||
moduleDirectories: ['node_modules', __dirname], | ||
testTimeout: 20000, | ||
setupFilesAfterEnv: ['./jest.setup.js'], | ||
testEnvironment: 'jest-environment-jsdom' | ||
} | ||
|
||
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js configuration, which is async | ||
module.exports = createJestConfig(customJestConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Optional: configure or set up a testing framework before each test. | ||
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` | ||
|
||
// Used for __tests__/testing-library.js | ||
// Learn more: https://github.com/testing-library/jest-dom | ||
import { loadEnvConfig } from '@next/env' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { TextDecoder, TextEncoder } from 'util' | ||
|
||
loadEnvConfig(process.cwd()) | ||
|
||
global.setImmediate = jest.useRealTimers | ||
global.TextDecoder = TextDecoder | ||
global.TextEncoder = TextEncoder | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation(query => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) | ||
|
||
window.IntersectionObserver = jest.fn(() => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn() | ||
})) | ||
|
||
jest.mock('next/dynamic', () => () => { | ||
const DynamicComponent = () => null | ||
DynamicComponent.displayName = 'LoadableComponent' | ||
DynamicComponent.preload = jest.fn() | ||
return DynamicComponent | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.