Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement: #14] Compatibility with Vite import.meta #24

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@rossyman/svelte-add-jest",
"version": "1.3.0",
"version": "1.3.1",
"description": "SvelteKit adder for Jest unit testing",
"license": "MIT",
"keywords": [
Expand Down
7 changes: 5 additions & 2 deletions preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class SvelteJestAdder extends Adder {

protected readonly REQUIRED_DEPENDENCIES: Dependencies = {
'@babel/core': {version: '^7.14.0', type: 'DEV'},
'@babel/preset-env': {version: '^7.14.0', type: 'DEV'},
'jest': {version: '^27.0.0', type: 'DEV'},
'babel-plugin-transform-vite-meta-env': {version: '^1.0.1', type: 'DEV'},
'babel-jest': {version: '^27.0.0', type: 'DEV'},
'svelte-jester': {version: '^2.0.1', type: 'DEV'},
'@testing-library/svelte': {version: '^3.0.0', type: 'DEV'},
Expand Down Expand Up @@ -243,7 +243,10 @@ class SvelteJestAdder extends Adder {

Preset
.editJson('package.json')
.merge({scripts: {'test': 'NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json', 'test:watch': 'npm run test -- --watch'}})
.merge({scripts: {
'test': 'NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json',
'test:watch': 'npm run test -- --watch'
}})
.withTitle('Adding test scripts to package.json');

Preset
Expand Down
13 changes: 2 additions & 11 deletions templates/.babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
"plugins": ["babel-plugin-transform-vite-meta-env"]
}
2 changes: 1 addition & 1 deletion templates/index-dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Index', () => {
describe('once the component has been rendered', () => {

test('should show the proper heading', () => {
expect(renderedComponent.getByText('Welcome to SvelteKit')).toBeInTheDocument();
expect(renderedComponent.getByText('SvelteKit', {exact: false})).toBeInTheDocument();
});

});
Expand Down
2 changes: 1 addition & 1 deletion templates/index-dom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Index', () => {
describe('once the component has been rendered', () => {

test('should show the proper heading', () => {
expect(renderedComponent.getByText('Welcome to SvelteKit')).toBeInTheDocument();
expect(renderedComponent.getByText('SvelteKit', {exact: false})).toBeInTheDocument();
});

});
Expand Down
17 changes: 12 additions & 5 deletions templates/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { render } from '@testing-library/svelte';
import Index from './index.svelte';

/**
* @jest-environment jsdom
*/

/**
* An example test suite outlining the usage of
* `describe()`, `beforeEach()`, `test()` and `expect()`
Expand All @@ -7,16 +14,16 @@

describe('Index', () => {

let isTestSuitePassing = false;
let renderedComponent;

beforeEach(() => {
isTestSuitePassing = true;
renderedComponent = render(Index);
});

describe('isTestSuitePassing', () => {
describe('once the component has been rendered', () => {

test('should be true', () => {
expect(isTestSuitePassing).toBe(true);
test('should show the proper heading', () => {
expect(renderedComponent.getByText('SvelteKit', {exact: false})).toBeDefined();
});

});
Expand Down
17 changes: 12 additions & 5 deletions templates/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { render, RenderResult } from '@testing-library/svelte';
import Index from './index.svelte';

/**
* @jest-environment jsdom
*/

/**
* An example test suite outlining the usage of
* `describe()`, `beforeEach()`, `test()` and `expect()`
Expand All @@ -7,16 +14,16 @@

describe('Index', () => {

let isTestSuitePassing = false;
let renderedComponent: RenderResult;

beforeEach(() => {
isTestSuitePassing = true;
renderedComponent = render(Index);
});

describe('isTestSuitePassing', () => {
describe('once the component has been rendered', () => {

test('should be true', () => {
expect(isTestSuitePassing).toBe(true);
test('should show the proper heading', () => {
expect(renderedComponent.getByText('SvelteKit', {exact: false})).toBeDefined();
});

});
Expand Down
5 changes: 4 additions & 1 deletion templates/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
},
"moduleNameMapper": {
"^\\$lib(.*)$": "<rootDir>/src/lib$1",
"^\\$app(.*)$": ["<rootDir>/.svelte-kit/dev/runtime/app$1", "<rootDir>/.svelte-kit/build/runtime/app$1"]
"^\\$app(.*)$": [
"<rootDir>/.svelte-kit/dev/runtime/app$1",
Copy link

@LeoUrzua LeoUrzua May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build folder was generated after npm run build and I am not sure how to generate the dev one but this is my folder content

image

I updated these lines to just "<rootDir>/.svelte-kit/runtime/app$1" and it was working for me, let me know what you think @rossyman

"<rootDir>/.svelte-kit/build/runtime/app$1"
]
},
"extensionsToTreatAsEsm": [".svelte"],
"moduleFileExtensions": ["js", "svelte"]
Expand Down