Skip to content

Commit

Permalink
refactor: async ky (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau authored Jan 31, 2023
1 parent 8e94970 commit d9137b9
Show file tree
Hide file tree
Showing 94 changed files with 8,325 additions and 27,532 deletions.
34 changes: 2 additions & 32 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
'use strict'

module.exports = function (api) {
const targets = '>1% or node >=10 and not ie 11 and not dead'
api.cache(true)
api.cacheDirectory = true

return {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'entry',
modules: 'commonjs',
bugfixes: true,
targets
}
]
],
plugins: [
'@babel/plugin-proposal-class-properties',
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true
}
]
]
}
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
}
11 changes: 2 additions & 9 deletions .depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
"@commitlint/config-conventional",
"@types/content-disposition",
"@types/debug",
"@types/expect-puppeteer",
"@types/jest",
"@types/jest-environment-puppeteer",
"@types/puppeteer",
"babel-jest",
"babel-loader",
"bufferutil",
"cross-blob",
"debug",
"husky",
"jest-puppeteer",
"puppeteer",
"ts-node",
"typedoc",
"typedoc-plugin-markdown",
"utf-8-validate",
"webpack-cli"
"webpack-cli",
"playwright-test"
]
}
16 changes: 3 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ module.exports = {
env: {
jest: true,
},
globals: {
browser: true,
page: true,
},
plugins: ['jest', 'unused-imports'],
plugins: ['unused-imports'],
rules: {
'array-bracket-newline': ['error', 'consistent'],
strict: ['error', 'safe'],
Expand Down Expand Up @@ -42,14 +38,7 @@ module.exports = {
'require-yield': 'error',
'max-nested-callbacks': ['error', 4],
'max-depth': ['error', 4],
'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
'space-before-function-paren': 'off',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'if' },
Expand Down Expand Up @@ -103,6 +92,7 @@ module.exports = {
files: ['*.spec.ts'],
rules: {
'max-nested-callbacks': ['error', 10], // allow describe/it nesting
'prefer-arrow-callback': 'off',
},
},
],
Expand Down
116 changes: 50 additions & 66 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,18 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Auth to Github Package Docker Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin
## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v2
id: cache-npm
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.OS }}-node-${{ matrix.node }}-
cache: 'npm'

- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
run: npm install -g npm && npm ci

# Start Bee Factory environment
- name: Start Bee Factory environment
Expand All @@ -64,55 +50,15 @@ jobs:
NODE_OPTIONS: '--no-experimental-fetch'
run: npm run bee -- --verbose --detach

- name: Run unit and integration tests for node
run: npm run test:node -- --detectOpenHandles

- name: Debug workflow if failed
if: failure()
run: |
KEYS=$(curl -sSf -X POST https://relay.tunshell.com/api/sessions)
curl -sSf -X POST -H "Content-Type: application/json" -d "{\"text\": \"**Bee JS**\nDebug -> \`sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com\`\"}" https://beehive.ethswarm.org/hooks/${{ secrets.WEBHOOK_KEY }}
echo "Connect to github actions node using"
echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com"
curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com
browser:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Auth to Github Package Docker Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin
## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v2
id: cache-npm
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.OS }}-node-${{ matrix.node }}-
- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci

# Start Bee Factory environment
- name: Start Bee Factory environment
run: npm run bee -- --detach
- name: Tests Node 18
if: matrix.node-version == '18.x'
env:
NODE_OPTIONS: '--no-experimental-fetch'
run: npm run test

- name: Run browser tests
run: npm run test:browser
- name: Tests non-Node 18
if: matrix.node-version != '18.x'
run: npm run test

- name: Debug workflow if failed
if: failure()
Expand All @@ -122,3 +68,41 @@ jobs:
echo "Connect to github actions node using"
echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com"
curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com
# browser:
# runs-on: ubuntu-latest
#
# strategy:
# matrix:
# node-version: [16.x]
#
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# with:
# fetch-depth: 1
#
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'
#
# - name: Install npm deps
# run: npm ci
#
# # Start Bee Factory environment
# - name: Start Bee Factory environment
# run: npm run bee -- --detach
#
# - name: Run browser tests
# run: npm run test:browser
#
# - name: Debug workflow if failed
# if: failure()
# run: |
# KEYS=$(curl -sSf -X POST https://relay.tunshell.com/api/sessions)
# curl -sSf -X POST -H "Content-Type: application/json" -d "{\"text\": \"**Bee JS**\nDebug -> \`sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com\`\"}" https://beehive.ethswarm.org/hooks/${{ secrets.WEBHOOK_KEY }}
# echo "Connect to github actions node using"
# echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com"
# curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com
5 changes: 5 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extension: ['ts'],
spec: 'test/**/*.spec.ts',
require: ['ts-node/register', './test/tests-setup.ts'],
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ Install project dependencies with
npm i
```

### Node 18

Node 18 came with its own fetch's native implementation called Undici. If you want to run bee-js tests under Node 18, then disable
the native's fetch implementation otherwise unit tests will fail as they capture HTTP calls with library called `nock` that does
not support native fetch yet.

```
export NODE_OPTIONS='--no-experimental-fetch'
```

### Test

The tests run in both context: node and dom with Jest.
Expand Down
5 changes: 0 additions & 5 deletions jest-puppeteer.config.js

This file was deleted.

85 changes: 0 additions & 85 deletions jest.config.ts

This file was deleted.

Loading

0 comments on commit d9137b9

Please sign in to comment.