Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snirsh committed Aug 1, 2024
1 parent 6ea2d10 commit 306e700
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/vitePlugin/vite-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const vitePlugin = require('./index');
describe('Carmi Vite Plugin', () => {
let mockPluginContext;


beforeEach(() => {
mockPluginContext = {
addWatchFile: jest.fn(),
Expand All @@ -11,14 +12,16 @@ describe('Carmi Vite Plugin', () => {
jest.clearAllMocks();
});

const getCarmiTestFile = async (plugin, mockCode) => await plugin.transform.call(mockPluginContext, mockCode, './src/vitePlugin/test.carmi.js');

it('transforms .carmi.js files', async () => {
const plugin = vitePlugin();
const mockCode = `
const { root } = require('carmi');
module.exports = { first: root.get(0) };
`;

const result = await plugin.transform.call(mockPluginContext, mockCode, 'test.carmi.js');
const result = await getCarmiTestFile(plugin, mockCode);

expect(result).toBeDefined();
expect(typeof result.code).toBe('string');
Expand All @@ -44,7 +47,7 @@ describe('Carmi Vite Plugin', () => {
module.exports = { first: root.get(0) };
`;

const result = await plugin.transform.call(mockPluginContext, mockCode, 'test.carmi.js');
const result = await getCarmiTestFile(plugin, mockCode);

expect(result).toBeDefined();
expect(result.code).toContain('function model');
Expand All @@ -71,7 +74,7 @@ describe('Carmi Vite Plugin', () => {
module.exports = { first: root.get(0) };
`;

const result = await plugin.transform.call(mockPluginContext, mockCode, 'test.carmi.js');
const result = await getCarmiTestFile(plugin, mockCode);

expect(result).toBeDefined();
expect(typeof result.code).toBe('string');
Expand Down

0 comments on commit 306e700

Please sign in to comment.