Skip to content

Commit

Permalink
Merge pull request #425 from crazy-max/jest-tmp
Browse files Browse the repository at this point in the history
jest: fix temp dir and rename fixtures folder
  • Loading branch information
crazy-max authored Jul 31, 2024
2 parents a8cf500 + eb838bd commit 3543c64
Show file tree
Hide file tree
Showing 82 changed files with 78 additions and 92 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 6 additions & 8 deletions __tests__/buildkit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
*/

import {describe, expect, jest, test, afterEach} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';

import {BuildKit} from '../../src/buildkit/buildkit';
import {Context} from '../../src/context';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildkit-config-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildkit-config-'));
const tmpName = path.join(tmpDir, '.tmpname-jest');

jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
fs.mkdirSync(tmpDir, {recursive: true});
return tmpDir;
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/buildx/bake.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as path from 'path';
import {Bake} from '../../src/buildx/bake';
import {BakeDefinition} from '../../src/types/buildx/bake';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
const fixturesDir = path.join(__dirname, '..', '.fixtures');

const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

Expand Down
14 changes: 6 additions & 8 deletions __tests__/buildx/bake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/

import {afterEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';

import {Bake} from '../../src/buildx/bake';
Expand All @@ -26,16 +27,13 @@ import {ExecOptions} from '@actions/exec';
import {BakeDefinition} from '../../src/types/buildx/bake';
import {BuildMetadata} from '../../src/types/buildx/build';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-bake-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-bake-'));
const tmpName = path.join(tmpDir, '.tmpname-jest');
const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-bake.json'), 'utf-8'));

jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
fs.mkdirSync(tmpDir, {recursive: true});
return tmpDir;
});

Expand Down
14 changes: 6 additions & 8 deletions __tests__/buildx/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
*/

import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';

import {Context} from '../../src/context';
import {Build} from '../../src/buildx/build';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-build-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-build-'));
const tmpName = path.join(tmpDir, '.tmpname-jest');
const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-build.json'), 'utf-8'));

jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
fs.mkdirSync(tmpDir, {recursive: true});
return tmpDir;
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/buildx/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {Exec} from '../../src/exec';

import {BuilderInfo} from '../../src/types/buildx/builder';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
const fixturesDir = path.join(__dirname, '..', '.fixtures');

jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
return {
Expand Down
11 changes: 5 additions & 6 deletions __tests__/buildx/buildx.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/

import {describe, expect, it} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as core from '@actions/core';

import {Buildx} from '../../src/buildx/buildx';
import {Build} from '../../src/buildx/build';
import {Bake} from '../../src/buildx/bake';
import {Exec} from '../../src/exec';

const fixturesDir = path.join(__dirname, '..', 'fixtures');

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-itg-'));

const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

Expand Down
14 changes: 6 additions & 8 deletions __tests__/buildx/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/

import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import * as semver from 'semver';

Expand All @@ -26,15 +27,12 @@ import {Exec} from '../../src/exec';

import {Cert, LocalState} from '../../src/types/buildx/buildx';

const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-'));
const tmpName = path.join(tmpDir, '.tmpname-jest');

jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
fs.mkdirSync(tmpDir, {recursive: true});
return tmpDir;
});

Expand Down
11 changes: 5 additions & 6 deletions __tests__/buildx/history.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/

import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';

import {Buildx} from '../../src/buildx/buildx';
import {Bake} from '../../src/buildx/bake';
import {Build} from '../../src/buildx/build';
import {History} from '../../src/buildx/history';
import {Exec} from '../../src/exec';

const fixturesDir = path.join(__dirname, '..', 'fixtures');

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-history-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-history-itg-'));

const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

Expand Down
8 changes: 4 additions & 4 deletions __tests__/buildx/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {Install} from '../../src/buildx/install';

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-install-'));

afterEach(function () {
rimraf.sync(tmpDir);
Expand Down
10 changes: 5 additions & 5 deletions __tests__/cache.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import path from 'path';
import {describe, expect, it} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';

import {Cache} from '../src/cache';

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'cache-jest');

const fixturesDir = path.join(__dirname, 'fixtures');
const fixturesDir = path.join(__dirname, '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'cache-itg-'));

describe('cache', () => {
it('github-repo', async () => {
Expand Down
14 changes: 6 additions & 8 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
* limitations under the License.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';
import {describe, expect, jest, it, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';

import {Context} from '../src/context';

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'context-jest');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
const tmpName = path.join(tmpDir, '.tmpname-jest');

jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
fs.mkdirSync(tmpDir, {recursive: true});
return tmpDir;
});

Expand Down
9 changes: 4 additions & 5 deletions __tests__/docker/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
import * as fs from 'fs';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as io from '@actions/io';
import osm = require('os');
Expand All @@ -25,10 +26,8 @@ import {Docker} from '../../src/docker/docker';

import {ConfigFile} from '../../src/types/docker/docker';

const fixturesDir = path.join(__dirname, '..', 'fixtures');

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-jest');
const fixturesDir = path.join(__dirname, '..', '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-docker-'));

afterEach(function () {
rimraf.sync(tmpDir);
Expand Down
7 changes: 4 additions & 3 deletions __tests__/docker/install.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/

import path from 'path';
import {jest, describe, expect, test, beforeEach, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';

import {Install} from '../../src/docker/install';
import {Docker} from '../../src/docker/docker';
import {Exec} from '../../src/exec';

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-'));

describe('install', () => {
const originalEnv = process.env;
Expand Down
8 changes: 4 additions & 4 deletions __tests__/docker/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

import {describe, expect, jest, test, beforeEach, afterEach, it} from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');

import {Install} from '../../src/docker/install';

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-'));

afterEach(function () {
rimraf.sync(tmpDir);
Expand Down
6 changes: 3 additions & 3 deletions __tests__/dockerhub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import * as path from 'path';
import {DockerHub} from '../src/dockerhub';
import {RepositoryResponse, RepositoryTagsResponse} from '../src/types/dockerhub';

import repoInfoFixture from './fixtures/dockerhub-repoinfo.json';
import repoTagsFixture from './fixtures/dockerhub-repotags.json';
import repoAllTagsFixture from './fixtures/dockerhub-repoalltags.json';
import repoInfoFixture from './.fixtures/dockerhub-repoinfo.json';
import repoTagsFixture from './.fixtures/dockerhub-repotags.json';
import repoAllTagsFixture from './.fixtures/dockerhub-repoalltags.json';

describe('getRepository', () => {
it('returns repo info', async () => {
Expand Down
9 changes: 4 additions & 5 deletions __tests__/github.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import {describe, expect, it, test} from '@jest/globals';
import fs from 'fs';
import * as path from 'path';
import os from 'os';
import path from 'path';

import {Buildx} from '../src/buildx/buildx';
import {Bake} from '../src/buildx/bake';
Expand All @@ -25,10 +26,8 @@ import {Exec} from '../src/exec';
import {GitHub} from '../src/github';
import {History} from '../src/buildx/history';

const fixturesDir = path.join(__dirname, 'fixtures');

// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'github-jest');
const fixturesDir = path.join(__dirname, '.fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'github-itg-'));

const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

Expand Down
6 changes: 3 additions & 3 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as core from '@actions/core';
import {GitHub} from '../src/github';
import {GitHubRepo} from '../src/types/github';

import repoFixture from './fixtures/github-repo.json';
import repoFixture from './.fixtures/github-repo.json';
jest.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise<GitHubRepo> => {
return <Promise<GitHubRepo>>(repoFixture as unknown);
});
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('actionsRuntimeToken', () => {
});
it('fixture', async () => {
process.env.ACTIONS_RUNTIME_TOKEN = fs
.readFileSync(path.join(__dirname, 'fixtures', 'runtimeToken.txt'))
.readFileSync(path.join(__dirname, '.fixtures', 'runtimeToken.txt'))
.toString()
.trim();
const runtimeToken = GitHub.actionsRuntimeToken;
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('printActionsRuntimeTokenACs', () => {
it('refs/heads/master', async () => {
const infoSpy = jest.spyOn(core, 'info');
process.env.ACTIONS_RUNTIME_TOKEN = fs
.readFileSync(path.join(__dirname, 'fixtures', 'runtimeToken.txt'))
.readFileSync(path.join(__dirname, '.fixtures', 'runtimeToken.txt'))
.toString()
.trim();
await GitHub.printActionsRuntimeTokenACs();
Expand Down
Loading

0 comments on commit 3543c64

Please sign in to comment.