Skip to content

Commit

Permalink
Merge pull request #175 from crazy-max/update-dev
Browse files Browse the repository at this point in the history
chore: update dev dependencies and workflow
  • Loading branch information
crazy-max committed Mar 22, 2022
2 parents 47c3651 + e99ab50 commit 1237c3e
Show file tree
Hide file tree
Showing 20 changed files with 2,569 additions and 40,224 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,23 @@
{
"env": {
"node": true,
"es2021": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"jest",
"prettier"
]
}
8 changes: 6 additions & 2 deletions __tests__/context.test.ts
@@ -1,3 +1,4 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -145,7 +146,7 @@ FOO=bar`
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbb\"bbb
bbbb"bbb
ccccccccc`,
'FOO=bar'
]);
Expand All @@ -167,19 +168,22 @@ describe('asyncForEach', () => {

describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
process.stdout.write = jest.fn() as typeof process.stdout.write;
});

// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});

// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});

// eslint-disable-next-line jest/expect-expect
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
Expand Down
4 changes: 3 additions & 1 deletion __tests__/flavor.test.ts
@@ -1,3 +1,4 @@
import {describe, expect, test} from '@jest/globals';
import {Flavor, Transform} from '../src/flavor';

describe('transform', () => {
Expand Down Expand Up @@ -165,14 +166,15 @@ describe('transform', () => {
} as Flavor,
false
]
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
])('given %p attributes', async (inputs: string[], expected: Flavor, invalid: boolean) => {
try {
const flavor = Transform(inputs);
expect(flavor).toEqual(expected);
} catch (err) {
if (!invalid) {
console.error(err);
}
// eslint-disable-next-line jest/no-conditional-expect
expect(true).toBe(invalid);
}
});
Expand Down
5 changes: 3 additions & 2 deletions __tests__/github.test.ts
@@ -1,8 +1,9 @@
import * as path from 'path';
import {describe, expect, jest, it} from '@jest/globals';
import * as github from '../src/github';

import * as repoFixture from './fixtures/repo.json';
jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetResponseData> => {
return <Promise<github.ReposGetResponseData>>require(path.join(__dirname, 'fixtures', 'repo.json'));
return <Promise<github.ReposGetResponseData>>(repoFixture as unknown);
});

describe('repo', () => {
Expand Down
12 changes: 7 additions & 5 deletions __tests__/meta.test.ts
@@ -1,3 +1,4 @@
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import * as dotenv from 'dotenv';
Expand All @@ -7,8 +8,9 @@ import * as github from '../src/github';
import {Meta, Version} from '../src/meta';
import {Context} from '@actions/github/lib/context';

import * as repoFixture from './fixtures/repo.json';
jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetResponseData> => {
return <Promise<github.ReposGetResponseData>>require(path.join(__dirname, 'fixtures', 'repo.json'));
return <Promise<github.ReposGetResponseData>>(repoFixture as unknown);
});

jest.spyOn(github, 'context').mockImplementation((): Context => {
Expand All @@ -20,7 +22,7 @@ jest.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => {
});

jest.mock('moment', () => {
return () => jest.requireActual('moment')('2020-01-10T00:30:00.000Z');
return () => (jest.requireActual('moment') as typeof import('moment'))('2020-01-10T00:30:00.000Z');
});

beforeEach(() => {
Expand All @@ -39,7 +41,7 @@ describe('isRawStatement', () => {
['{{ raw }}', true],
['{{ raw}}', true],
['{{raw}}', true],
])('given %p pattern ', async (pattern: string, expected: boolean) => {
])('given %p pattern', async (pattern: string, expected: boolean) => {
expect(Meta.isRawStatement(pattern)).toEqual(expected);
});
});
Expand Down Expand Up @@ -3219,7 +3221,7 @@ describe('json', () => {
}
}
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: {}) => {
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exJSON: unknown) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const context = github.context();

Expand Down Expand Up @@ -3524,7 +3526,7 @@ describe('bake', () => {
}
}
]
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: {}) => {
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exBakeDefinition: unknown) => {
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
const context = github.context();

Expand Down
5 changes: 4 additions & 1 deletion __tests__/tag.test.ts
@@ -1,3 +1,4 @@
import {describe, expect, test} from '@jest/globals';
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';

describe('transform', () => {
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('transform', () => {
if (!invalid) {
console.error(err);
}
// eslint-disable-next-line jest/no-conditional-expect
expect(true).toBe(invalid);
}
});
Expand Down Expand Up @@ -425,14 +427,15 @@ describe('parse', () => {
{} as Tag,
true
]
])('given %p event ', async (s: string, expected: Tag, invalid: boolean) => {
])('given %p event', async (s: string, expected: Tag, invalid: boolean) => {
try {
const tag = Parse(s);
expect(tag).toEqual(expected);
} catch (err) {
if (!invalid) {
console.error(err);
}
// eslint-disable-next-line jest/no-conditional-expect
expect(true).toBe(invalid);
}
});
Expand Down
8 changes: 4 additions & 4 deletions hack/build.Dockerfile → dev.Dockerfile
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.3-labs
# syntax=docker/dockerfile:1

ARG NODE_VERSION
ARG NODE_VERSION=12

FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache cpio findutils git
Expand Down Expand Up @@ -55,10 +55,10 @@ RUN --mount=type=bind,target=.,rw \
FROM scratch AS format-update
COPY --from=format /out /

FROM deps AS format-validate
FROM deps AS lint
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run format-check
yarn run lint

FROM deps AS test
ENV RUNNER_TEMP=/tmp/github_runner
Expand Down

0 comments on commit 1237c3e

Please sign in to comment.