Skip to content

Commit

Permalink
[enhancement: #14] Compatibility with Vite import.meta
Browse files Browse the repository at this point in the history
  • Loading branch information
rossyman committed Sep 9, 2021
1 parent bd18366 commit 6a2ca34
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
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",
"<rootDir>/.svelte-kit/build/runtime/app$1"
]
},
"extensionsToTreatAsEsm": [".svelte"],
"moduleFileExtensions": ["js", "svelte"]
Expand Down

0 comments on commit 6a2ca34

Please sign in to comment.