Skip to content

Commit e3e5d6e

Browse files
authored
Merge pull request #21 from uploadcare/chore/fix-test
chore: fix convertToUploadcareQualityString test
2 parents bc5c2ed + d6884fd commit e3e5d6e

File tree

5 files changed

+24
-74
lines changed

5 files changed

+24
-74
lines changed
Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
name: Ship js Manual Prepare
2-
on:
3-
issue_comment:
4-
types: [created]
2+
on: workflow_dispatch
53
jobs:
64
manual_prepare:
7-
if: |
8-
github.event_name == 'issue_comment' &&
9-
(github.event.comment.author_association == 'member' || github.event.comment.author_association == 'owner') &&
10-
startsWith(github.event.comment.body, '@shipjs prepare')
115
runs-on: ubuntu-latest
126
steps:
137
- uses: actions/checkout@v2
@@ -16,49 +10,12 @@ jobs:
1610
ref: main
1711
- uses: actions/setup-node@v2
1812
with:
19-
node-version: '14'
20-
- run: |
21-
if [ -f "yarn.lock" ]; then
22-
yarn install
23-
else
24-
npm install
25-
fi
13+
node-version: '16'
14+
- run: yarn install --frozen-lockfile
2615
- run: |
2716
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2817
git config --global user.name "github-actions[bot]"
29-
- run: npm run release -- --yes --no-browse
18+
- run: yarn release --yes --no-browse
3019
env:
3120
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3221
SLACK_INCOMING_HOOK: ${{ secrets.SLACK_INCOMING_HOOK }}
33-
34-
create_done_comment:
35-
if: success()
36-
needs: manual_prepare
37-
runs-on: ubuntu-latest
38-
steps:
39-
- uses: actions/github-script@v3
40-
with:
41-
github-token: ${{ secrets.GITHUB_TOKEN }}
42-
script: |
43-
github.issues.createComment({
44-
issue_number: context.issue.number,
45-
owner: context.repo.owner,
46-
repo: context.repo.repo,
47-
body: "@${{github.actor}} `shipjs prepare` done"
48-
})
49-
50-
create_fail_comment:
51-
if: cancelled() || failure()
52-
needs: manual_prepare
53-
runs-on: ubuntu-latest
54-
steps:
55-
- uses: actions/github-script@v3
56-
with:
57-
github-token: ${{ secrets.GITHUB_TOKEN }}
58-
script: |
59-
github.issues.createComment({
60-
issue_number: context.issue.number,
61-
owner: context.repo.owner,
62-
repo: context.repo.repo,
63-
body: "@${{github.actor}} `shipjs prepare` fail"
64-
})

.github/workflows/shipjs-trigger.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@ jobs:
1515
ref: main
1616
- uses: actions/setup-node@v2
1717
with:
18-
node-version: '14'
1918
registry-url: "https://registry.npmjs.org"
20-
- run: |
21-
if [ -f "yarn.lock" ]; then
22-
yarn install
23-
else
24-
npm install
25-
fi
19+
node-version: '16'
20+
- run: yarn install --frozen-lockfile
2621
- run: npx shipjs trigger
2722
env:
2823
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-and-lint.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,14 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12-
with:
13-
fetch-depth: 0
14-
ref: main
1512
- uses: actions/setup-node@v2
1613
with:
17-
node-version: '14'
18-
- run: |
19-
if [ -f "yarn.lock" ]; then
20-
yarn install
21-
else
22-
npm install
23-
fi
24-
- run: |
25-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
26-
git config --global user.name "github-actions[bot]"
27-
- run: yarn test
28-
- run: yarn lint
29-
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31-
SLACK_INCOMING_HOOK: ${{ secrets.SLACK_INCOMING_HOOK }}
14+
node-version: '16'
15+
- name: Install dependencies
16+
working-directory: ./
17+
run: yarn install --frozen-lockfile
18+
- name: Run tests
19+
run: yarn test
20+
- name: Run lint
21+
run: yarn lint
22+

src/__tests__/convert-to-uploadcare-quality-string.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { convertToUploadcareQualityString } from '../utils/helpers';
22

33
describe('convertToUploadcareQualityString', () => {
4-
it('should map 0 to lightest', () => {
5-
expect(convertToUploadcareQualityString(0)).toBe('lightest');
4+
it('should map 1 to lightest', () => {
5+
expect(convertToUploadcareQualityString(1)).toBe('lightest');
66
});
77

88
it('should map 38 to lightest', () => {
@@ -16,4 +16,9 @@ describe('convertToUploadcareQualityString', () => {
1616
it('should map 100 to best', () => {
1717
expect(convertToUploadcareQualityString(100)).toBe('best');
1818
});
19+
20+
it('should map falsy values to smart', () => {
21+
expect(convertToUploadcareQualityString()).toBe('smart');
22+
expect(convertToUploadcareQualityString(0)).toBe('smart');
23+
});
1924
});

src/utils/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export function convertToUploadcareQualityString(
6868
requestedQuality?: number
6969
): string {
7070
// If any particular quality has not been requested, we use the smart quality mode.
71+
// zero quality is treated as no quality, so we use smart.
72+
// see https://nextjs.org/docs/api-reference/next/image#quality
7173
if (!requestedQuality) {
7274
return 'smart';
7375
}

0 commit comments

Comments
 (0)