Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add feature e2e tests and improve overall testing #289

Merged
merged 177 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
d105aab
chore: feature test i18n
exreplay Nov 7, 2020
1d028f9
Merge branch 'development' into chore/feature-testing
exreplay Nov 7, 2020
fd9482d
Merge branch 'development' into chore/feature-testing
exreplay Nov 7, 2020
f80dd9a
refactor: added close function to server
exreplay Nov 8, 2020
244eb3e
refactor: use isProd instead of process env
exreplay Nov 8, 2020
405c6b7
chore: added jest env to js files
exreplay Nov 8, 2020
351fafb
chore: updated jest config and added setup script
exreplay Nov 8, 2020
320e927
fix: use distPath instead of distDir
exreplay Nov 8, 2020
ebe6621
chore: added first feature test for i18n
exreplay Nov 8, 2020
228a39a
chore: added jest puppeteer config
exreplay Nov 8, 2020
6a67ba4
chore: added NODE_ENV env variable
exreplay Nov 8, 2020
f6be0e1
chore: updated circleci config
exreplay Nov 8, 2020
7fe7825
chore: added puppeteer orb
exreplay Nov 8, 2020
d8231b5
chore: update circleci config
exreplay Nov 8, 2020
4d8ae61
chore: updated jest puppeteer config
exreplay Nov 8, 2020
eda55ad
chore: disable headless
exreplay Nov 8, 2020
38310cc
updated ci config
exreplay Nov 8, 2020
43be1a0
updated ci config
exreplay Nov 8, 2020
88b36d4
fix: fixed circleci config
exreplay Nov 8, 2020
ba1844a
chore: updated circleci config
exreplay Nov 8, 2020
0433918
chore: updated circleci config
exreplay Nov 8, 2020
9f52263
chore: added puppeteer install to install job
exreplay Nov 8, 2020
b250671
chore: first checkout
exreplay Nov 8, 2020
450e6c0
fix: remove orb and added run command to install
exreplay Nov 8, 2020
240cf14
fix: moved install deps to test job
exreplay Nov 8, 2020
7769f05
chore: added build to test
exreplay Nov 8, 2020
be126e2
chore: use package.json for checksum
exreplay Nov 8, 2020
b670dbc
chore: removed build job
exreplay Nov 8, 2020
3724fc6
added install
exreplay Nov 8, 2020
ba49384
chore: removed install
exreplay Nov 8, 2020
d0df82f
check node_env
exreplay Nov 8, 2020
afbb5f3
chore: set NODE_ENV to test
exreplay Nov 8, 2020
e376136
refactor: remove distDir
exreplay Nov 8, 2020
ed1461d
refactor: move aver config
exreplay Nov 8, 2020
c4be8a8
log distPath
exreplay Nov 8, 2020
60f6a20
moved NODE_ENV
exreplay Nov 8, 2020
34d3536
updated ci config
exreplay Nov 8, 2020
bf533dc
log dirname
exreplay Nov 8, 2020
38c110d
fix: fixed cli tests
exreplay Nov 8, 2020
2e52ecb
fix: added typing to args
exreplay Nov 8, 2020
6856d29
fix: fixed typings and removed test files from exclude
exreplay Nov 8, 2020
ed14133
chore: include __tests__ dir
exreplay Nov 8, 2020
9209615
chore: added check for i18n mixin
exreplay Nov 8, 2020
352402f
refactor: added testFeature function
exreplay Nov 8, 2020
bbe2b47
test: added feature test for vue-progressbar
exreplay Nov 8, 2020
1ea1a58
chore: pass all logs to consola and pause logging
exreplay Nov 8, 2020
f75d390
fix: fixed thickness in vue-progressbar test
exreplay Nov 8, 2020
201f3c9
refactor: added options for testFeature
exreplay Nov 14, 2020
153b1fd
refactor: added feature test for dev build
exreplay Nov 14, 2020
7818810
refactor: added close functions to builder and renderer and core
exreplay Nov 14, 2020
4287786
refactor: added 404 check
exreplay Nov 14, 2020
ad108f1
Merge branch 'development' into chore/feature-testing
exreplay Dec 6, 2020
67c5699
linting
exreplay Dec 6, 2020
8d7bf12
linting
exreplay Dec 6, 2020
c51d0be
linting
exreplay Dec 6, 2020
a556a5c
linting
exreplay Dec 6, 2020
9dcb27f
fix: added build scripts
exreplay Dec 6, 2020
217ad4b
test: added build scripts tests
exreplay Dec 6, 2020
ec907a1
fix: fixed config file
exreplay Dec 6, 2020
8c133c2
fix: fixed config
exreplay Dec 6, 2020
ed3808b
fix: fixed types
exreplay Dec 6, 2020
9ca3d3b
refactor: added watchers array
exreplay Dec 11, 2020
92648c4
refactor: do not open browser in feature tests
exreplay Dec 11, 2020
76d31d4
Merge branch 'development' into chore/feature-testing
exreplay Dec 11, 2020
b109fc2
chore: remove unused deps
exreplay Dec 11, 2020
fc0ce6c
fix: disable thread loder for circle ci tests
exreplay Dec 11, 2020
708de97
fix: fixed typings for api extractor
exreplay Dec 11, 2020
956a488
ci: updated circleci config
exreplay Dec 11, 2020
e292f37
ci: added missing job
exreplay Dec 11, 2020
65f80e5
ci: updated build job
exreplay Dec 11, 2020
438b65f
test: reset puppeteer browser after all
exreplay Dec 11, 2020
e31e713
ci: fixed config
exreplay Dec 11, 2020
ee660f8
fix: always run dev test first
exreplay Dec 11, 2020
bd9cdb4
ci: do not depend on build job
exreplay Dec 11, 2020
d7d16fa
test: istanbul ignore open browser file
exreplay Dec 19, 2020
6bd00c1
refactor: use optional chaining
exreplay Dec 19, 2020
e9565e8
test: added tests for mailer plugin
exreplay Dec 19, 2020
45e3c05
fix: fixed typings
exreplay Dec 20, 2020
a01394e
test: added tests for mongodb plugin
exreplay Dec 20, 2020
50c2980
test: fixed mongodb test
exreplay Dec 20, 2020
55227ed
fix: do not run mailer plugin on build
exreplay Dec 20, 2020
8ce7ed0
test: added test for websocket plugin
exreplay Dec 20, 2020
931c544
test: added csrf tests
exreplay Dec 25, 2020
2fbd312
chore: allow missing page config
exreplay Dec 25, 2020
638ce9d
chore: updated types for createRenderer
exreplay Dec 25, 2020
8621cb6
test: added test for create renderer
exreplay Dec 25, 2020
60c9703
test: clear cookies after tests
exreplay Dec 25, 2020
f834638
test: added helmet tests
exreplay Dec 25, 2020
6d56db2
test: removed test sequencer
exreplay Dec 25, 2020
1c2fd92
test: added back sequencer
exreplay Dec 25, 2020
50da2d7
chore: enabled logging and updated watcher
exreplay Dec 26, 2020
5a4d8f8
chore: ignore storage folders
exreplay Dec 26, 2020
98c2eea
chore: remove console.log
exreplay Dec 26, 2020
d73aee0
test: remove storage folder after test
exreplay Dec 26, 2020
3fff0d9
test: added tests for typescript plugin
exreplay Dec 26, 2020
a93cf10
chore: log error log
exreplay Dec 26, 2020
c6b974f
chore: endabled console log
exreplay Dec 26, 2020
88c2e9a
test: clear log before all
exreplay Dec 26, 2020
da1378a
ci: use circlei test reporter
exreplay Dec 26, 2020
6631167
ci: fixed junit install
exreplay Dec 26, 2020
0eb4c07
ci: fix test steps
exreplay Dec 26, 2020
1a68f1b
test: added tests for typescript runtime package
exreplay Dec 26, 2020
d10d6fd
fix: promisify server close for proper tear down
exreplay Dec 27, 2020
bac7709
chore: removed test sequencer
exreplay Dec 27, 2020
50081a3
chore: added close and updated types
exreplay Dec 27, 2020
a59cd77
test: updated dev e2e test
exreplay Dec 27, 2020
4182ead
chore: added keepDist and keepLogs and do not clear logs in beforeAll
exreplay Dec 27, 2020
ed5250e
fix: fixed dst path for entries when in subfolder
exreplay Dec 27, 2020
d31cba8
fix: clear hooks after build
exreplay Dec 27, 2020
4fcfce5
test: added tests for plugins
exreplay Dec 27, 2020
cf0a40a
test: disabled show console logs
exreplay Dec 27, 2020
d5ee623
chore: removed console log
exreplay Dec 27, 2020
8878d56
feat: added before and after close hooks
exreplay Dec 27, 2020
599674c
test: check mocked calles in after close hook
exreplay Dec 27, 2020
57cb386
test: added tests for session plugin
exreplay Dec 27, 2020
a7dd790
fix: split by entries folder not just the word
exreplay Dec 28, 2020
73e80a6
chore: removed default config
exreplay Dec 28, 2020
e28c710
chore: use distDir
exreplay Dec 28, 2020
e863c94
fix: changed import for dev and hot middlewares
exreplay Dec 28, 2020
0783925
test: added tests for plugin entries hmr
exreplay Dec 28, 2020
71d93df
chore: disable show logs
exreplay Dec 28, 2020
2b4f580
ci: do not updated lockfile
exreplay Dec 28, 2020
7434c9c
test: fix dev test
exreplay Dec 28, 2020
466ab28
test: added test for static builds
exreplay Dec 28, 2020
cd9e810
chore: disable show console logs
exreplay Dec 28, 2020
bc3bcc0
test: added tests for service worker
exreplay Dec 28, 2020
87effb8
test: added test for webpack config hooks
exreplay Dec 28, 2020
265b729
fix: clear stuff after close
exreplay Dec 28, 2020
db40671
test: added istanbul ignore for requireModule
exreplay Dec 28, 2020
d5299a9
test: added istanbul ignore for requireModule
exreplay Dec 28, 2020
fca8c92
test: added test for transpile deps
exreplay Dec 30, 2020
dce9f7f
chore: removed options
exreplay Dec 30, 2020
4999e6e
fix: fixed service worker tests
exreplay Dec 30, 2020
5ebff09
chore: disable options
exreplay Dec 30, 2020
c8a986a
fix: fixed plugins entries hmr test
exreplay Dec 30, 2020
84792c8
fix: use read file instead of require
exreplay Dec 31, 2020
0ba6479
chore: added test for error
exreplay Dec 31, 2020
03cd939
test: added css extract test
exreplay Dec 31, 2020
afdef98
fix: do not start server in static mode
exreplay Dec 31, 2020
1e5bd4b
chore: await run commands
exreplay Dec 31, 2020
0cd2e47
fix: do not cache when css extract is active
exreplay Dec 31, 2020
166f027
test: added test for css and postcss
exreplay Jan 1, 2021
b3128ef
test: added dotenv test
exreplay Jan 1, 2021
39792c4
test: added tests for www class
exreplay Jan 1, 2021
a0c9d29
test: moved test www to server and added robots.txt test
exreplay Jan 1, 2021
6376a89
test: added test for webpack aliases
exreplay Jan 1, 2021
f383a58
test: added test for open browser
exreplay Jan 1, 2021
a44eabd
chore: do not log message in test
exreplay Jan 1, 2021
98cb959
test: changed back path
exreplay Jan 1, 2021
aec873c
test: changed dotenv test
exreplay Jan 1, 2021
776e2d4
fix: fixed typings for webpack alias
exreplay Jan 1, 2021
a24dc19
fix: exit process on build error
exreplay Jan 1, 2021
5448ce8
test: added test for files changed plugin
exreplay Jan 1, 2021
97f0cf1
test: remove env test check
exreplay Jan 1, 2021
5cb5445
test: added test for additional extensions
exreplay Jan 2, 2021
409ebec
test: added test for asyncData hook
exreplay Jan 2, 2021
a8378ae
test: check for store file to include extensions
exreplay Jan 2, 2021
6d3a1b6
linting
exreplay Jan 2, 2021
b20a5ce
test: check for asyncData class hook
exreplay Jan 2, 2021
473d4ec
chore: remove show console logs
exreplay Jan 2, 2021
fcf90bf
ci: increase memory limit
exreplay Jan 2, 2021
3946a1b
ci: added junit dep as resporter
exreplay Jan 2, 2021
8650755
refactor: added internal aver config type and the normal config type …
exreplay Jan 3, 2021
49aa4c7
fix: fixed persisted state on server side
exreplay Jan 3, 2021
109dcd7
test: added test for vuex
exreplay Jan 3, 2021
f89c9d0
fix: added next for error middleware to work
exreplay Jan 3, 2021
9e2d79f
test: added tests for favicon, middleware entry file and error handling
exreplay Jan 3, 2021
c3aba76
chore: removed options
exreplay Jan 3, 2021
14cef47
test: renamed to babel loader and updated tests
exreplay Jan 3, 2021
1ef9e86
test: added test for clear server cache
exreplay Jan 3, 2021
fbfe3d7
refactor: added types for babel confg param
exreplay Jan 4, 2021
c8c418e
test: added test for build errors
exreplay Jan 4, 2021
a6d1f3b
test: added vue-meta tests
exreplay Jan 4, 2021
d00ce23
test: added test for copy webpack plugin
exreplay Jan 4, 2021
915ecc0
test: check error when service-worker.js is missing
exreplay Jan 4, 2021
b7b0147
chore: updated types and chaining
exreplay Jan 5, 2021
04b526f
test: hooks should not fail on false config
exreplay Jan 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 72 additions & 31 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,84 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:latest
version: 2.1

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:latest

jobs:
install:
<<: *defaults
steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- v1-averjs-{{ checksum "package.json" }}
- run: yarn install --frozen-lockfile
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

- run: yarn lint

key: v1-averjs-{{ checksum "package.json" }}
- persist_to_workspace:
root: ~/
paths:
- repo

build:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn build-scripts

- run: yarn build

lint:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run: yarn lint

test:
<<: *defaults
steps:
- attach_workspace:
at: ~/
- run:
name: Install Headless Chrome dependencies
command: |
sudo apt-get install -yq \
gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- run:
name: Run tests with JUnit as reporter
command: yarn jest --ci --runInBand --reporters=default --reporters=jest-junit
environment:
JEST_JUNIT_OUTPUT_DIR: ./reports/junit/
NODE_OPTIONS: --max_old_space_size=4096
NODE_ENV: test
CIRCLE_CI: true
- run:
name: Run code coverage
command: yarn codecov
- store_test_results:
path: ./reports/junit/
- store_artifacts:
path: ./reports/junit

# run tests!
- run: yarn test
workflows:
version: 2.1
test:
jobs:
- install
- build:
requires:
- install
- lint:
requires:
- install
- test:
requires:
- install
28 changes: 18 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
env: {
jest: true
},
globals: {
jestPuppeteer: true
},
extends: [
'standard',
'eslint:recommended',
Expand Down Expand Up @@ -85,18 +88,23 @@ module.exports = {
},
{
files: ['**/*.js', '**/*.vue'],
extends: ['@averjs', 'plugin:prettier/recommended'],
env: {
jest: true
},
extends: ['@averjs'],
rules: {
'space-before-function-paren': 'off'
indent: 'off',
'space-before-function-paren': 'off',
'vue/script-indent': 'off'
}
},
{
files: ['packages/@averjs/vue-app/templates/**/*.js'],
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2015
},
extends: ['plugin:lodash-template/recommended-with-script']
}
// {
// files: ['packages/@averjs/vue-app/templates/**/*.js'],
// parserOptions: {
// parser: 'babel-eslint',
// ecmaVersion: 2015
// },
// extends: ['plugin:lodash-template/recommended-with-script']
// }
]
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ verdaccio
packages/test
.changelog
temp
scripts-build
scripts-build
__tests__/**/storage
43 changes: 43 additions & 0 deletions __tests__/features/additional-extensions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { testFeature } from '../utils/feature';
import fs from 'fs';
import path from 'path';

testFeature('additional-extensions', currentDir => {
test('should add the additional extensions to entries regex', async () => {
const response = await page.goto('http://localhost:3000');
const content = await page.content();
expect(await response?.text()).toContain(
'<span>server entry works</span><span>i18n entry works</span><span>app entry works</span>'
);
expect(content).toContain(
'<span>client entry works</span><span>i18n entry works</span><span>app entry works</span>'
);

const appContent = fs.readFileSync(
path.resolve(currentDir, './node_modules/.cache/averjs/app.js'),
'utf-8'
);
const clientContent = fs.readFileSync(
path.resolve(currentDir, './node_modules/.cache/averjs/entry-client.js'),
'utf-8'
);
const entryServerContent = fs.readFileSync(
path.resolve(currentDir, './node_modules/.cache/averjs/entry-server.js'),
'utf-8'
);
const i18nContent = fs.readFileSync(
path.resolve(currentDir, './node_modules/.cache/averjs/i18n.js'),
'utf-8'
);
const storeContent = fs.readFileSync(
path.resolve(currentDir, './node_modules/.cache/averjs/store/index.js'),
'utf-8'
);

expect(appContent).toContain('(js|ts)');
expect(clientContent).toContain('(js|ts)');
expect(entryServerContent).toContain('(js|ts)');
expect(i18nContent).toContain('(js|ts)');
expect(storeContent).toContain('(js|ts)');
});
});
10 changes: 10 additions & 0 deletions __tests__/features/alias.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { testFeature } from '../utils/feature';

testFeature('alias', () => {
test('should resolve webpack aliases correctly', async () => {
await page.goto('http://localhost:3000');
expect(await page.content()).toContain(
'<div id="app"><div><span>vuex</span><span>src</span><span>root</span><span>components</span><span>mixins</span><span>resources</span><span>[{"path":"/","name":"home"}]</span><span>test</span></div></div>'
);
});
});
27 changes: 27 additions & 0 deletions __tests__/features/async-data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { testFeature } from '../utils/feature';

testFeature('async-data', () => {
test('should fetch data before rendering component on page change', async () => {
await page.goto('http://localhost:3000');
await (await page.$('a'))?.click();
const watchDog = page.waitForFunction('window.status === "ready"');
await watchDog;
expect(await page.content()).toContain(
'<div id="app"><div>some async data</div></div>'
);
});

test('should fetch data before ssr', async () => {
const response = await page.goto('http://localhost:3000/test');
expect(await response?.text()).toContain(
'<div id="app" data-server-rendered="true"><div>some async data</div></div>'
);
});

test('should have the asyncData class hook registered', async () => {
const response = await page.goto('http://localhost:3000/test-class');
expect(await response?.text()).toContain(
'<div id="app" data-server-rendered="true"><div>some async data</div></div>'
);
});
});
109 changes: 109 additions & 0 deletions __tests__/features/babel-loader.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { rebuild, testFeature } from '../utils/feature';
import fs from 'fs-extra';
import path from 'path';

testFeature(
'babel-loader',
() => {
test('should transpile given deps correctly', async () => {
await page.goto('http://localhost:3000');
const content = await page.content();

expect(content).toContain(
'<div id="app"><span>test</span><span>another test</span><div>should be compiled</div></div>'
);
});

test('should transpile deps with regex correctly', async () => {
await rebuild({
webpack: {
transpileDependencies: [/package-to-transpile/]
}
});

await page.goto('http://localhost:3000');
const content = await page.content();

expect(content).toContain(
'<div id="app"><span>test</span><span>another test</span><div>should be compiled</div></div>'
);
});

test('should ignore non string and non regex', async () => {
await rebuild({
webpack: {
transpileDependencies: [
/package-to-transpile/,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {}
]
}
});

await page.goto('http://localhost:3000');
const content = await page.content();

expect(content).toContain(
'<div id="app"><span>test</span><span>another test</span><div>should be compiled</div></div>'
);
});

test('should throw error when the package is missing in the transpileDependencies array', async () => {
try {
await rebuild({
webpack: {
transpileDependencies: []
}
});
} catch (error) {
expect(error).toContain("SyntaxError: Unexpected token 'export'");
}
});

test('should fallback to empty array', async () => {
try {
await rebuild({
webpack: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
transpileDependencies: null
}
});
} catch (error) {
expect(error).toContain("SyntaxError: Unexpected token 'export'");
}
});

test('should call the babel function correctly', async () => {
const babel = jest.fn();
await rebuild({
webpack: {
babel
}
});
expect(babel.mock.calls.length).toBe(2);
expect(babel.mock.calls[0]).toEqual(
expect.arrayContaining([{ isServer: false }, { buildTarget: 'client' }])
);
expect(babel.mock.calls[1]).toEqual(
expect.arrayContaining([{ isServer: true }, { buildTarget: 'server' }])
);
});
},
{},
currentDir => {
beforeAll(() => {
fs.copySync(
path.resolve(currentDir, './package-to-transpile'),
path.resolve(process.cwd(), './node_modules/package-to-transpile')
);
});
afterAll(() => {
fs.removeSync(
path.resolve(process.cwd(), './node_modules/package-to-transpile')
);
});
}
);
15 changes: 15 additions & 0 deletions __tests__/features/copy-webpack.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { testFeature } from '../utils/feature';
import fs from 'fs-extra';
import path from 'path';

testFeature('copy-webpack', currentDir => {
const logoPath = path.resolve(currentDir, './public/images/logo.png');

afterAll(() => {
fs.removeSync(path.resolve(currentDir, './public'));
});

test('should copy images in resources folder to public folder', () => {
expect(fs.existsSync(logoPath)).toBeTruthy();
});
});
Loading