Skip to content

Commit

Permalink
Merge pull request #1036 from gperdomor/fix/ci
Browse files Browse the repository at this point in the history
ci: fix tests
  • Loading branch information
gperdomor committed Apr 23, 2024
2 parents 24ad3d1 + 39e6e56 commit e42edd2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jest.preset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const nxPreset = require('@nx/jest/preset').default;

module.exports = { ...nxPreset, testEnvironment: 'node', coverageReporters: ['html', 'json'] };
module.exports = { ...nxPreset, testEnvironment: 'node', coverageReporters: ['html', 'json'], clearMocks: true };
5 changes: 3 additions & 2 deletions packages/container-metadata/src/lib/meta.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContextProxyFactory, RepoMetadata, RepoProxyFactory, RunnerContext } from '@nx-tools/ci-context';
import { workspaceRoot } from '@nx/devkit';
import * as dotenv from 'dotenv';
import * as fs from 'node:fs';
import * as path from 'node:path';
Expand Down Expand Up @@ -41,8 +42,8 @@ beforeEach(() => {
});

// workaround for https://github.com/nrwl/nx/issues/20330
const projectDir = path.join(__dirname, '..', '..');
if (process.env.PWD !== projectDir) {
const projectDir = `${workspaceRoot}/packages/container-metadata`;
if (process.cwd() !== projectDir) {
process.chdir(projectDir);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ describe('Docker Engine', () => {
adapter = new Docker();
});

beforeAll(() => {
jest.spyOn(console, 'info').mockImplementation(() => true);
jest.spyOn(console, 'log').mockImplementation(() => true);
jest.spyOn(console, 'warn').mockImplementation(() => true);
});

describe('getArgs', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ describe('Podman Engine', () => {
adapter = new Podman();
});

beforeAll(() => {
jest.spyOn(console, 'info').mockImplementation(() => true);
jest.spyOn(console, 'log').mockImplementation(() => true);
jest.spyOn(console, 'warn').mockImplementation(() => true);
});

describe('getArgs', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'node:path';
import * as semver from 'semver';
import * as podman from './podman';

const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
const tmpNameSync = path.join('/tmp/.podman-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
const metadata = `{
"containerimage.config.digest": "sha256:059b68a595b22564a1cbc167af369349fdc2ecc1f7bc092c2235cbf601a795fd",
Expand All @@ -19,7 +19,7 @@ jest.mock('../../context', () => {
__esModule: true,
...originalModule,
tmpDir: jest.fn(() => {
const tmpDir = path.join('/tmp/.docker-build-push-jest').split(path.sep).join(path.posix.sep);
const tmpDir = path.join('/tmp/.podman-build-push-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, { recursive: true });
}
Expand Down
12 changes: 12 additions & 0 deletions packages/nx-container/src/executors/build/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RepoMetadata } from '@nx-tools/ci-context';
import { workspaceRoot } from '@nx/devkit';
import mockedEnv, { RestoreFn } from 'mocked-env';
import * as path from 'node:path';
import { run } from './executor';
Expand Down Expand Up @@ -33,6 +34,12 @@ jest.mock('@nx-tools/ci-context', () => {
describe('Build Executor', () => {
let restore: RestoreFn;

beforeAll(() => {
jest.spyOn(console, 'info').mockImplementation(() => true);
jest.spyOn(console, 'log').mockImplementation(() => true);
jest.spyOn(console, 'warn').mockImplementation(() => true);
});

beforeEach(() => {
restore = mockedEnv({
CI_PIPELINE_SOURCE: 'push',
Expand All @@ -43,6 +50,11 @@ describe('Build Executor', () => {
CI_PIPELINE_ID: '1234',
CI_PIPELINE_IID: '5678',
});

// workaround for https://github.com/nrwl/nx/issues/20330
if (process.cwd() !== workspaceRoot) {
process.chdir(workspaceRoot);
}
});

afterEach(() => {
Expand Down

0 comments on commit e42edd2

Please sign in to comment.