Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions examples/plugins/src/file-size/src/file-size.plugin.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { vol } from 'memfs';
import { beforeEach, describe, expect, it } from 'vitest';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { executePlugin } from '@code-pushup/core';
import {
auditSchema,
categoryRefSchema,
pluginConfigSchema,
} from '@code-pushup/models';
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
import {
type PluginOptions,
audits,
Expand All @@ -27,24 +27,31 @@ const projectJson = JSON.stringify(
2,
);
const testJs = `
const str = 'Hello World'
const num = 42;
const obj = ${projectJson};
`;
const str = 'Hello World';
const num = 42;
const obj = ${projectJson};
`;

describe('create', () => {
const workDir = path.join(
'tmp',
'int-tests',
'examples-plugins',
'package-json',
);

const baseOptions: PluginOptions = {
directory: '/',
directory: workDir,
};

beforeEach(() => {
vol.fromJSON(
{
'project.json': projectJson,
'src/test.js': testJs,
},
MEMFS_VOLUME,
);
beforeAll(async () => {
await mkdir(workDir, { recursive: true });
await writeFile(path.join(workDir, 'project.json'), projectJson);
await writeFile(path.join(workDir, 'test.js'), testJs);
});

afterAll(async () => {
await rm(workDir, { recursive: true, force: true });
});

it('should return valid PluginConfig', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { vol } from 'memfs';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { executePlugin } from '@code-pushup/core';
import {
Expand All @@ -7,7 +8,6 @@ import {
pluginConfigSchema,
pluginReportSchema,
} from '@code-pushup/models';
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
import { audits, pluginSlug as slug } from './constants.js';
import { type PluginOptions, create } from './package-json.plugin.js';
import {
Expand All @@ -18,17 +18,24 @@ import {
} from './scoring.js';

describe('create-package-json', () => {
const workDir = path.join(
'tmp',
'int-tests',
'examples-plugins',
'package-json',
);

const baseOptions: PluginOptions = {
directory: '/',
directory: workDir,
};

beforeEach(() => {
vol.fromJSON(
{
'package.json': '{}',
},
MEMFS_VOLUME,
);
beforeAll(async () => {
await mkdir(workDir, { recursive: true });
await writeFile(path.join(workDir, 'package.json'), '{}');
});

afterAll(async () => {
await rm(workDir, { recursive: true, force: true });
});

it('should return valid PluginConfig', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/plugins/vitest.int.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default defineConfig({
include: ['src/**/*.int.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['../../global-setup.ts'],
setupFiles: [
'../../testing/test-setup/src/lib/fs.mock.ts',
'../../testing/test-setup/src/lib/git.mock.ts',
'../../testing/test-setup/src/lib/console.mock.ts',
'../../testing/test-setup/src/lib/reset.mocks.ts',
Expand Down