jest: fix temp dir

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-07-31 11:01:57 +02:00
parent a8cf50098a
commit aa8033de8f
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
14 changed files with 59 additions and 73 deletions

View File

@ -15,22 +15,20 @@
*/ */
import {describe, expect, jest, test, afterEach} from '@jest/globals'; import {describe, expect, jest, test, afterEach} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import {BuildKit} from '../../src/buildkit/buildkit'; import {BuildKit} from '../../src/buildkit/buildkit';
import {Context} from '../../src/context'; import {Context} from '../../src/context';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildkit-config-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildkit-config-jest');
const tmpName = path.join(tmpDir, '.tmpname-jest'); const tmpName = path.join(tmpDir, '.tmpname-jest');
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true}); fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir; return tmpDir;
}); });

View File

@ -15,8 +15,9 @@
*/ */
import {afterEach, describe, expect, it, jest, test} from '@jest/globals'; import {afterEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import {Bake} from '../../src/buildx/bake'; import {Bake} from '../../src/buildx/bake';
@ -27,15 +28,12 @@ import {BakeDefinition} from '../../src/types/buildx/bake';
import {BuildMetadata} from '../../src/types/buildx/build'; import {BuildMetadata} from '../../src/types/buildx/build';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-bake-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-bake-jest');
const tmpName = path.join(tmpDir, '.tmpname-jest'); const tmpName = path.join(tmpDir, '.tmpname-jest');
const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-bake.json'), 'utf-8')); const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-bake.json'), 'utf-8'));
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true}); fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir; return tmpDir;
}); });

View File

@ -15,23 +15,21 @@
*/ */
import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals'; import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import {Context} from '../../src/context'; import {Context} from '../../src/context';
import {Build} from '../../src/buildx/build'; import {Build} from '../../src/buildx/build';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-build-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-build-jest');
const tmpName = path.join(tmpDir, '.tmpname-jest'); const tmpName = path.join(tmpDir, '.tmpname-jest');
const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-build.json'), 'utf-8')); const metadata = JSON.parse(fs.readFileSync(path.join(fixturesDir, 'metadata-build.json'), 'utf-8'));
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true}); fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir; return tmpDir;
}); });

View File

@ -15,8 +15,9 @@
*/ */
import {describe, expect, it} from '@jest/globals'; import {describe, expect, it} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import {Buildx} from '../../src/buildx/buildx'; import {Buildx} from '../../src/buildx/buildx';
@ -25,9 +26,7 @@ import {Bake} from '../../src/buildx/bake';
import {Exec} from '../../src/exec'; import {Exec} from '../../src/exec';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-itg-'));
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

View File

@ -15,8 +15,9 @@
*/ */
import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals'; import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import * as semver from 'semver'; import * as semver from 'semver';
@ -27,14 +28,11 @@ import {Exec} from '../../src/exec';
import {Cert, LocalState} from '../../src/types/buildx/buildx'; import {Cert, LocalState} from '../../src/types/buildx/buildx';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-buildx-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
const tmpName = path.join(tmpDir, '.tmpname-jest'); const tmpName = path.join(tmpDir, '.tmpname-jest');
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true}); fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir; return tmpDir;
}); });

View File

@ -15,8 +15,9 @@
*/ */
import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals'; import {afterEach, beforeEach, describe, expect, it, jest, test} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import {Buildx} from '../../src/buildx/buildx'; import {Buildx} from '../../src/buildx/buildx';
import {Bake} from '../../src/buildx/bake'; import {Bake} from '../../src/buildx/bake';
@ -25,9 +26,7 @@ import {History} from '../../src/buildx/history';
import {Exec} from '../../src/exec'; import {Exec} from '../../src/exec';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-history-itg-'));
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-history-jest');
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

View File

@ -15,15 +15,15 @@
*/ */
import {describe, expect, it, jest, test, afterEach} from '@jest/globals'; import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import osm = require('os'); import osm = require('os');
import {Install} from '../../src/buildx/install'; import {Install} from '../../src/buildx/install';
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'buildx-install-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
afterEach(function () { afterEach(function () {
rimraf.sync(tmpDir); rimraf.sync(tmpDir);

View File

@ -14,15 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
import path from 'path';
import {describe, expect, it} from '@jest/globals'; import {describe, expect, it} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {Cache} from '../src/cache'; 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', () => { describe('cache', () => {
it('github-repo', async () => { it('github-repo', async () => {

View File

@ -14,21 +14,19 @@
* limitations under the License. * 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 {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'; import {Context} from '../src/context';
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'context-jest');
const tmpName = path.join(tmpDir, '.tmpname-jest'); const tmpName = path.join(tmpDir, '.tmpname-jest');
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => { jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true}); fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir; return tmpDir;
}); });

View File

@ -15,7 +15,8 @@
*/ */
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals'; 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 path from 'path';
import * as io from '@actions/io'; import * as io from '@actions/io';
import osm = require('os'); import osm = require('os');
@ -26,9 +27,7 @@ import {Docker} from '../../src/docker/docker';
import {ConfigFile} from '../../src/types/docker/docker'; import {ConfigFile} from '../../src/types/docker/docker';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-docker-'));
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-jest');
afterEach(function () { afterEach(function () {
rimraf.sync(tmpDir); rimraf.sync(tmpDir);

View File

@ -14,15 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
import path from 'path';
import {jest, describe, expect, test, beforeEach, afterEach} from '@jest/globals'; 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 {Install} from '../../src/docker/install';
import {Docker} from '../../src/docker/docker'; import {Docker} from '../../src/docker/docker';
import {Exec} from '../../src/exec'; import {Exec} from '../../src/exec';
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-itg-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest');
describe('install', () => { describe('install', () => {
const originalEnv = process.env; const originalEnv = process.env;

View File

@ -15,15 +15,15 @@
*/ */
import {describe, expect, jest, test, beforeEach, afterEach, it} from '@jest/globals'; import {describe, expect, jest, test, beforeEach, afterEach, it} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import osm = require('os'); import osm = require('os');
import {Install} from '../../src/docker/install'; import {Install} from '../../src/docker/install';
// prettier-ignore const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'docker-install-'));
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-install-jest');
afterEach(function () { afterEach(function () {
rimraf.sync(tmpDir); rimraf.sync(tmpDir);

View File

@ -16,7 +16,8 @@
import {describe, expect, it, test} from '@jest/globals'; import {describe, expect, it, test} from '@jest/globals';
import fs from 'fs'; import fs from 'fs';
import * as path from 'path'; import os from 'os';
import path from 'path';
import {Buildx} from '../src/buildx/buildx'; import {Buildx} from '../src/buildx/buildx';
import {Bake} from '../src/buildx/bake'; import {Bake} from '../src/buildx/bake';
@ -26,9 +27,7 @@ import {GitHub} from '../src/github';
import {History} from '../src/buildx/history'; import {History} from '../src/buildx/history';
const fixturesDir = path.join(__dirname, 'fixtures'); const fixturesDir = path.join(__dirname, 'fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'github-itg-'));
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'github-jest');
const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip; const maybe = !process.env.GITHUB_ACTIONS || (process.env.GITHUB_ACTIONS === 'true' && process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) ? describe : describe.skip;

View File

@ -15,16 +15,15 @@
*/ */
import {afterEach, describe, expect, test} from '@jest/globals'; import {afterEach, describe, expect, test} from '@jest/globals';
import * as fs from 'fs'; import fs from 'fs';
import os from 'os';
import path from 'path'; import path from 'path';
import * as rimraf from 'rimraf'; import * as rimraf from 'rimraf';
import {OCI} from '../../src/oci/oci'; import {OCI} from '../../src/oci/oci';
const fixturesDir = path.join(__dirname, '..', 'fixtures'); const fixturesDir = path.join(__dirname, '..', 'fixtures');
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'oci-oci-'));
// prettier-ignore
const tmpDir = path.join(process.env.TEMP || '/tmp', 'docker-jest');
afterEach(function () { afterEach(function () {
rimraf.sync(tmpDir); rimraf.sync(tmpDir);