Skip to content

Commit

Permalink
chore: refactor test use ts
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Apr 26, 2023
1 parent 0d4ec66 commit 3a74515
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 12 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
159 changes: 155 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"prepublishOnly": "npm run build",
"build": "rollup -c --bundleConfigAsCjs",
"test": "jest"
"test": "npm run buil && jest"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -57,7 +57,9 @@
"rollup-plugin-node-externals": "^5.0.0",
"rollup-plugin-ts": "^3.0.2",
"sass": "^1.62.1",
"svelte": "^3.58.0"
"svelte": "^3.58.0",
"ts-jest": "^29.1.0",
"typescript": "^4.9.5"
},
"dependencies": {
"svelte-loader": "^3.1.5",
Expand Down
2 changes: 1 addition & 1 deletion src/taroSvelteLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ function taroSvelteLoader(source) {
svelteLoader.call(this, source)
}

module.exports = taroSvelteLoader
export default taroSvelteLoader
File renamed without changes.
9 changes: 4 additions & 5 deletions test/loader.spec.js → test/loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const taroSvelteLoader = require('../lib/taroSvelteLoader')
import taroSvelteLoader from '../lib/taroSvelteLoader'

jest.mock('@tarojs/webpack5-runner/dist/utils/component', () => ({
componentConfig: {
includes: new Set()
}
}))

function testLoader(source, callback, query, version = 2) {
function testLoader(source: string, callback: (err: Error | null, code: string, map: string) => void) {
return done => {
const addedDependencies = new Set();

Expand All @@ -16,6 +16,7 @@ function testLoader(source, callback, query, version = 2) {
}
args.push(addedDependencies);
try {
// @ts-ignore
callback(...args);
} catch (err) {
expect(callbackSpy).toBeCalled();
Expand All @@ -36,9 +37,7 @@ function testLoader(source, callback, query, version = 2) {
cacheable: cacheableSpy,
async: () => callbackSpy,
addDependency: dependencySpy,
resourcePath: '<nil>',
version,
query
resourcePath: '<nil>'
},
source,
null
Expand Down

0 comments on commit 3a74515

Please sign in to comment.