-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for v-model and some tests (#10)
- Loading branch information
Showing
8 changed files
with
1,448 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
moduleFileExtensions: ["js", "jsx", "json", "vue"], | ||
transform: { | ||
"^.+\\.vue$": "vue-jest", | ||
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": | ||
"jest-transform-stub", | ||
"^.+\\.jsx?$": "babel-jest" | ||
}, | ||
moduleNameMapper: { | ||
"^@/(.*)$": "<rootDir>/src/$1" | ||
}, | ||
snapshotSerializers: ["jest-serializer-vue"], | ||
testMatch: [ | ||
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)" | ||
], | ||
testURL: "http://localhost/" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,13 @@ | ||
{ | ||
"name": "vue-prism-editor", | ||
"version": "0.0.1", | ||
"description": "A dead simple code editor with syntax highlighting and line numbers.", | ||
"keywords": [ | ||
"vue", | ||
"editor", | ||
"code editor", | ||
"prism" | ||
], | ||
"main": "dist/VuePrismEditor.umd.js", | ||
"module": "dist/VuePrismEditor.common.js", | ||
"unpkg": "dist/VuePrismEditor.umd.min.js", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"serve": "vue-cli-service serve", | ||
"build": "vue-cli-service build --dest site", | ||
"lint": "vue-cli-service lint", | ||
"build:lib": "vue-cli-service build --target lib --name VuePrismEditor ./src/components/Editor.vue && rimraf dist/demo.html", | ||
"lint": "vue-cli-service lint" | ||
"test:unit": "vue-cli-service test:unit" | ||
}, | ||
"author": { | ||
"name": "Mesut Koca", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/koca/vue-prism-editor.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/koca/vue-prism-editor/issues" | ||
}, | ||
"homepage": "https://github.com/koca/vue-prism-editor#readme", | ||
"license": "MIT", | ||
"dependencies": { | ||
"dom-iterator": "^1.0.0", | ||
"escape-html": "^1.0.3", | ||
|
@@ -39,8 +17,12 @@ | |
"@vue/cli-plugin-babel": "^3.0.0-beta.15", | ||
"@vue/cli-plugin-eslint": "^3.0.0-beta.15", | ||
"@vue/cli-plugin-pwa": "^3.0.0-beta.15", | ||
"@vue/cli-plugin-unit-jest": "^3.0.3", | ||
"@vue/cli-service": "^3.0.0-beta.15", | ||
"@vue/eslint-config-prettier": "^3.0.0-beta.15", | ||
"@vue/test-utils": "^1.0.0-beta.20", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-jest": "^23.0.1", | ||
"prismjs": "^1.15.0", | ||
"register-service-worker": "^1.5.2", | ||
"rimraf": "^2.6.2", | ||
|
@@ -52,5 +34,28 @@ | |
"> 1%", | ||
"last 2 versions", | ||
"not ie <= 8" | ||
] | ||
], | ||
"unpkg": "dist/VuePrismEditor.umd.min.js", | ||
"module": "dist/VuePrismEditor.common.js", | ||
"main": "dist/VuePrismEditor.umd.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/koca/vue-prism-editor.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/koca/vue-prism-editor/issues" | ||
}, | ||
"homepage": "https://github.com/koca/vue-prism-editor#readme", | ||
"license": "MIT", | ||
"keywords": [ | ||
"vue", | ||
"editor", | ||
"code editor", | ||
"prism" | ||
], | ||
"description": "A dead simple code editor with syntax highlighting and line numbers.", | ||
"author": { | ||
"name": "Mesut Koca", | ||
"email": "[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
env: { | ||
jest: true | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { mount } from "@vue/test-utils"; | ||
import Editor from "@/components/Editor.vue"; | ||
import "prismjs"; | ||
import { compileToFunctions } from "vue-template-compiler"; | ||
|
||
document.createRange = jest.fn(); | ||
global.getSelection = jest.fn(); | ||
global.getSelection.mockReturnValue({ | ||
rangeCount: 1, | ||
getRangeAt: jest.fn().mockReturnValue({ | ||
cloneRange: jest.fn().mockReturnValue({ | ||
selectNodeContents: jest.fn(), | ||
setEnd: jest.fn(), | ||
setStart: jest.fn() | ||
}) | ||
}) | ||
}); | ||
|
||
describe("Editor.vue", () => { | ||
test("renders", () => { | ||
let code = "initialCode"; | ||
const wrapper = mount(Editor, { | ||
propsData: { code } | ||
}); | ||
expect(wrapper.html()).toContain(code); | ||
}); | ||
test("emits change event", () => { | ||
let code = "console.log('test')"; | ||
const wrapper = mount(Editor); | ||
const $pre = wrapper.find(".prism-editor__code"); | ||
$pre.element.innerHTML = code; | ||
$pre.trigger("keyup"); | ||
expect(wrapper.emitted("change")[0]).toEqual([code]); | ||
}); | ||
|
||
test("v-model works", () => { | ||
const compiled = compileToFunctions( | ||
'<div><Editor class="foo" v-model="code" /></div>' | ||
); | ||
const wrapper = mount(compiled, { | ||
data: () => ({ | ||
code: "test" | ||
}), | ||
stubs: { | ||
Editor | ||
} | ||
}); | ||
const $pre = wrapper.find("pre"); | ||
|
||
expect(wrapper.vm.code).toEqual("test"); | ||
$pre.element.innerHTML = "works"; | ||
wrapper.vm.$children[0].$emit("change", "works"); | ||
expect(wrapper.vm.code).toEqual("works"); | ||
}); | ||
}); |
Oops, something went wrong.