Skip to content

Commit

Permalink
Merge pull request #108 from transloadit/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
kvz authored Oct 1, 2024
2 parents e6113c6 + 163b510 commit 0184a17
Show file tree
Hide file tree
Showing 31 changed files with 7,344 additions and 3,685 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

7 changes: 0 additions & 7 deletions .flowconfig

This file was deleted.

78 changes: 41 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,57 @@ on:
types:
- opened
- synchronize
env:
SKIP_YARN_COREPACK_CHECK: true

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@main
- name: Cache apt packages
uses: actions/cache@v3
with:
node-version: 18.x
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: sergioramos/yarn-actions/install@master
${{ runner.os }}-apt-
- uses: actions/setup-node@v4
with:
frozen-lockfile: true
- name: Install playwright dependencies
run: |
sudo -HE env DEBIAN_FRONTEND=noninteractive apt-get --option Dpkg::Options::=--force-confnew -qy --no-install-recommends --allow-downgrades --allow-remove-essential --allow-change-held-packages install \
fonts-ipafont-gothic \
fonts-liberation \
fonts-tlwg-loma-otf \
fonts-wqy-zenhei \
libdrm2 \
libfontconfig \
libfreetype6 \
libgbm1 \
msttcorefonts \
ttf-ubuntu-font-family \
xfonts-cyrillic \
xfonts-scalable \
&& true
npx playwright install --with-deps chromium
node-version: '20.x'
cache: 'yarn'
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: yarn install --immutable
- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Lint
run: |
yarn lint
run: yarn lint
- name: Build
run: |
yarn build
- name: Test
run: yarn build
- name: Run Unit Tests
run: yarn test:unit
- name: E2E Test
env:
TRANSLOADIT_ACCESS_KEY: ${{ secrets.TRANSLOADIT_ACCESS_KEY }}
TRANSLOADIT_ACCESS_KEY: '${{ secrets.TRANSLOADIT_ACCESS_KEY }}'
run: |
yarn test
if [ "${TRANSLOADIT_ACCESS_KEY}" = "" ]; then
echo "TRANSLOADIT_ACCESS_KEY is not set. Skipping E2E tests."
else
npx playwright install --with-deps chromium
yarn test:e2e
fi
- name: Upload Coverage Report
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
node_modules/
/build/
/flow/
test-results/
/tests/screen-*
env.sh
auth_key.js
flow-osx-latest.zip
npm-debug.log
.yarn/install-state.gz
coverage/
5 changes: 0 additions & 5 deletions .prettierignore

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierrc.json

This file was deleted.

12 changes: 6 additions & 6 deletions .vscode/jquery-sdk.code-workspace
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {}
"folders": [
{
"path": ".."
}
],
"settings": {}
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
123 changes: 123 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [
"build/",
"css/transloadit.css",
"package.json",
"coverage/**",
"js/dep/",
"**/node_modules/",
"tests/fixtures/",
"**/test-results/"
]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessConstructor": "error",
"noUselessLoneBlockStatements": "error",
"noUselessRename": "error",
"noUselessTernary": "error",
"noUselessUndefinedInitialization": "error",
"noWith": "error"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noNewSymbol": "error",
"noSelfAssign": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "error",
"useIsNan": "error"
},
"security": {
"noGlobalEval": "error"
},
"style": {
"noCommaOperator": "error",
"noYodaExpression": "error",
"useBlockStatements": "error",
"useConsistentBuiltinInstantiation": "error",
"useSingleVarDeclarator": "error"
},
"suspicious": {
"noCatchAssign": "error",
"noClassAssign": "error",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDoubleEquals": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noLabelVar": "error",
"noRedeclare": "error",
"noSelfCompare": "error",
"noShadowRestrictedNames": "error",
"noSparseArray": "error",
"noUnsafeNegation": "error",
"useValidTypeof": "error"
}
},
"ignore": [
"build/**",
"css/transloadit.css",
"package.json",
"coverage/**",
"js/dep/**",
"node_modules/**"
]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
},
"globals": ["jQuery", "testhost", "casper", "arguments"]
}
}
6 changes: 3 additions & 3 deletions js/lib/Assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Assembly.prototype._assemblyRequest = function (query, cb) {
self._inAssemblyRequest = false
cb()
},
error: function (xhr, status, jsonpErr) {
error: function (_xhr, status, jsonpErr) {
var retriesExhausted = attemptCount >= self._statusFetchRetries
var err = self._connectionError(retriesExhausted)
err.reason = 'Could not fetch assembly status.'
Expand Down Expand Up @@ -186,7 +186,7 @@ Assembly.prototype._createSocket = function (cb) {
}
})

this._socket.on('connect', function (event) {
this._socket.on('connect', function (_event) {
self._socketConnected = true

if (self._socketReconnectInterval) {
Expand Down Expand Up @@ -236,7 +236,7 @@ Assembly.prototype._createSocket = function (cb) {
self._onResult(stepName, result)
})

this._socket.on('disconnect', function (event) {
this._socket.on('disconnect', function (_event) {
self._socket.close()
self.onDisconnect()
})
Expand Down
2 changes: 1 addition & 1 deletion js/lib/FilePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FilePreview {
})
}

removeAllFiles(file) {
removeAllFiles(_file) {
this._$ul.find('li').remove()
}

Expand Down
2 changes: 1 addition & 1 deletion js/lib/InternetConnectionChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InternetConnectionChecker {
}
}

onlineCheck(cb) {
onlineCheck(_cb) {
const online = typeof window.navigator.onLine !== 'undefined' ? window.navigator.onLine : true

if (this._isOnline && !online) {
Expand Down
8 changes: 4 additions & 4 deletions js/lib/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Modal {
</div>
<p class="error-details"></p>
</div>
</div>`
</div>`,
).appendTo('body')

this.$.extend(this._$modal, {
Expand Down Expand Up @@ -105,7 +105,7 @@ class Modal {

if (!err.message) {
err.message = `${this._i18n.translate('errors.unknown')} ${this._i18n.translate(
'errors.tryAgain'
'errors.tryAgain',
)}`
}

Expand Down Expand Up @@ -152,7 +152,7 @@ class Modal {
})
}

renderCancelling(received, expected) {
renderCancelling(_received, _expected) {
this._$modal.$label.text(this._i18n.translate('cancelling'))
}

Expand Down Expand Up @@ -234,7 +234,7 @@ class Modal {
mbReceived,
mbExpected,
this._uploadRate,
this._durationLeft
this._durationLeft,
)
this._$modal.$label.text(txt)
}
Expand Down
Loading

0 comments on commit 0184a17

Please sign in to comment.