Skip to content

Commit cb71ac6

Browse files
authored
Merge pull request #1 from JaredCE/javascript-testing-frameworks
Snippets for other testing frameworks
2 parents 803eb6d + ca6b0ce commit cb71ac6

File tree

12 files changed

+986
-106
lines changed

12 files changed

+986
-106
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy Extension
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Publish VS Code Extension
12+
# You may pin to the exact commit or the version.
13+
# uses: HaaLeo/publish-vscode-extension@c1a0486c5a3eed24e8c21d4e37889a7c4c60c443
14+
uses: HaaLeo/publish-vscode-extension@v1
15+
with:
16+
# Personal access token
17+
pat: ${{secrets.VSCODE_PUBLISHER_ACCESS_TOKEN}}
18+
# Use the registry API at this base URL
19+
registryUrl: https://marketplace.visualstudio.com
20+
# Set this option to "true" to package your extension but do not publish it.
21+
dryRun: true

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [{
4+
"name": "Run Extension",
5+
"type": "extensionHost",
6+
"request": "launch",
7+
"runtimeExecutable": "${execPath}",
8+
"args": [
9+
"--extensionDevelopmentPath=${workspaceFolder}"
10+
],
11+
"outFiles": [
12+
"${workspaceFolder}/out/**/*.js"
13+
],
14+
// "preLaunchTask": "npm: watch"
15+
}
16+
]
17+
}

.vscodeignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.gitignore
2+
.github/**
3+
.vscode/**
24
LICENSE
3-
CHANGELOG.md
5+
CHANGELOG.md

README.md

Lines changed: 143 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,164 @@
22
## VS Code JavaScript testing framework snippets
33
-------------------
44

5-
<!-- [![Version](https://vsmarketplacebadge.apphb.com/version/xabikos.JasmineSnippets.svg)](https://marketplace.visualstudio.com/items?itemName=xabikos.JasmineSnippets)
6-
[![Installs](https://vsmarketplacebadge.apphb.com/installs/xabikos.JasmineSnippets.svg)](https://marketplace.visualstudio.com/items?itemName=xabikos.JasmineSnippets)
7-
[![Ratings](https://vsmarketplacebadge.apphb.com/rating/xabikos.JasmineSnippets.svg)](https://marketplace.visualstudio.com/items?itemName=xabikos.JasmineSnippets) -->
5+
<!-- [![Version](https://vsmarketplacebadge.apphb.com/version/JaredE.javascript-test-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=JaredE.javascript-test-snippets)
6+
[![Installs](https://vsmarketplacebadge.apphb.com/installs/JaredE.javascript-test-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=JaredE.javascript-test-snippets)
7+
[![Ratings](https://vsmarketplacebadge.apphb.com/rating/JaredE.javascript-test-snippets.svg)](https://marketplace.visualstudio.com/items?itemName=JaredE.javascript-test-snippets) -->
88

9-
This extension contains code snippets for various JavaScript testing frameworks, based off of the [Jasmine][jasmine] test framework and is based on the awesome [sublime-jasmine][sublime-jusmine] package by [@NicoSantangelo][NicoSantangelo].
9+
This extension contains code snippets for the three main JavaScript testing frameworks: Jasmine, Jest and Mocha. You can switch between the code snippets available by setting your preferred framework at a User or Workspace level in the settings page. You can also choose the quote style (*"*, *'* or *\`*) you prefer at a User or Workspace level for your `desc` methods.
1010

11-
[Original][original] credit should goto [xabikos][xabikos] for writing this extension.
12-
13-
## Installation
14-
15-
In order to install an extension you need to launch the Command Palette (Ctrl + Shift + P or Cmd + Shift + P) and type Extensions.
16-
There you have either the option to show the already installed snippets or install new ones.
11+
[Original][original] credit should goto [xabikos][xabikos] for writing this extension which was based off of the [Jasmine][jasmine] test framework and is based on the awesome [sublime-jasmine][sublime-jusmine] package by [@NicoSantangelo][NicoSantangelo].
1712

1813
## Supported languages (file extensions)
1914
* JavaScript (.js)
2015
* TypeScript (.ts)
21-
* TypeScript React (.tsx)
22-
* JavaScript React (.jsx)
2316

2417
## Snippets
2518

2619
Below is a list of all available snippets and the triggers of each one. The **** means the `TAB` key.
2720

28-
### Specs
21+
### Jest Commands
22+
| Trigger | Content |
23+
| -------: | ------- |
24+
| `aa→` | afterAll method |
25+
| `aaa→` | afterAllAsync method |
26+
| `ae→` | afterEach method |
27+
| `aea→` | afterEachAsync method |
28+
| `ba→` | beforeAll method |
29+
| `baa→` | beforeAllAsync method |
30+
| `be→` | beforeEach method |
31+
| `bea→` | beforeEachAsync method |
32+
| `desc→` | describe method |
33+
| `it→` | it method |
34+
| `ait→` | itAsync method |
35+
| `aat→` | afterAllTimeout method |
36+
| `aet→` | afterEachTimeout method |
37+
| `bat→` | beforeAllTimeout method |
38+
| `bet→` | beforeEachTimeout method |
39+
| `desce→` | describeEach method |
40+
| `desco→` | describeOnly method |
41+
| `desceo→` | describeOnlyEach method |
42+
| `descsk→` | describeSkip method |
43+
| `descse→` | describeSkipEach method |
44+
| `exp→` | expect method |
45+
| `expe→` | expect.extend method |
46+
| `expa→` | expect.anything method |
47+
| `exy→` | expect.any method |
48+
| `ac→` | expect.arrayContaining method |
49+
| `ass→` | expect.assertions method |
50+
| `ha→` | expect.hasAssertions method |
51+
| `nac→` | expect.not.arrayContaining method |
52+
| `noc→` | expect.not.objectContaining(object) method |
53+
| `nsc→` | expect.not.stringContaining method |
54+
| `nsm→` | expect.not.stringMatching method |
55+
| `oc→` | expect.objectContaining method |
56+
| `sc→` | expect.stringContaining method |
57+
| `sm→` | expect.stringMatching method |
58+
| `ass→` | expect.addSnapshotSerializer method |
59+
| `ito→` | itOnly method |
60+
| `itsk→` | itSkip method |
61+
| `not→` | not method |
62+
| `res→` | resolves method |
63+
| `rej→` | rejects method |
64+
| `te→` | test method |
65+
| `tea→` | testAsync method |
66+
| `tee→` | testEach method |
67+
| `teo→` | testOnly method |
68+
| `teoe→` | testOnlyEach method |
69+
| `tsk→` | testSkip method |
70+
| `tske→` | testSkipEach method |
71+
| `ttodo→` | testToDo method |
72+
| `tb→` | toBe method |
73+
| `tbc→` | toHaveBeenCalled method |
74+
| `bct→` | toHaveBeenCalledTimes method |
75+
| `bcw→` | toHaveBeenCalledWith method |
76+
| `bclw→` | toHaveBeenLastCalledWith method |
77+
| `bncw→` | toHaveBeenNthCalledWith method |
78+
| `hr→` | toHaveReturned method |
79+
| `hrt→` | toHaveReturnedTimes method |
80+
| `hrw→` | toHaveReturnedWith method |
81+
| `hlrw→` | toHaveLastReturnedWith method |
82+
| `tnrw→` | toHaveNthReturnedWith method |
83+
| `hl→` | toHaveLength method |
84+
| `hp→` | toHaveProperty method |
85+
| `bclt→` | toBeCloseTo method |
86+
| `tbd→` | toBeDefined method |
87+
| `tbf→` | toBeFalsy method |
88+
| `gt→` | toBeGreaterThan method |
89+
| `gte→` | toBeGreaterThanOrEqual method |
90+
| `lt→` | toBeLessThan method |
91+
| `lte→` | toBeLessThanOrEqual method |
92+
| `bio→` | toBeInstanceOf method |
93+
| `bnu→` | toBeNull method |
94+
| `btr→` | toBeTruthy method |
95+
| `bund→` | toBeUndefined method |
96+
| `bnan→` | toBeNaN method |
97+
| `tcon→` | toContain method |
98+
| `tce→` | toContainEqual method |
99+
| `te→` | toEqual method |
100+
| `tm→` | toMatch method |
101+
| `tmo→` | toMatchObject method |
102+
| `tms→` | toMatchSnapshot method |
103+
| `tmis→` | toMatchInlineSnapshot method |
104+
| `tse→` | toStrictEqual method |
105+
| `ttr→` | toThrow method |
106+
| `ttrer→` | toThrowErrorMatchingSnapshot method |
107+
| `tterrin→` | toThrowErrorMatchingInlineSnapshot method |
108+
109+
### Jasmine Commands
110+
29111
| Trigger | Content |
30112
| -------: | ------- |
31-
| `desc→` | describe method |
32-
| `xdesc→` | xdescribe method |
33-
| `fdesc→` | fdescribe method |
34-
| `it→` | it method |
35-
| `ait→` | async it method |
36-
| `xit→` | xit method |
37-
| `fit→` | fit method |
38-
| `ae→` | after each method |
39-
| `aa→` | after all methods |
40-
| `be→` | before each method |
41-
| `ba→` | before all methods |
113+
| `aa→` | afterAll method |
114+
| `aaa→` | afterAllAsync method |
115+
| `ae→` | afterEach method |
116+
| `aea→` | afterEachAsync method |
117+
| `ba→` | beforeAll method |
118+
| `baa→` | beforeAllAsync method |
119+
| `be→` | beforeEach method |
120+
| `bea→` | beforeEachAsync method |
121+
| `desc→` | describe method |
122+
| `it→` | it method |
123+
| `ait→` | itAsync method |
124+
| `aat→` | afterAllTimeout method |
125+
| `aet→` | afterEachTimeout method |
126+
| `bat→` | beforeAllTimeout method |
127+
| `bet→` | beforeEachTimeout method |
128+
| `exp→` | expect method |
129+
| `expa→` | expectAsync method |
130+
| `fa→` | fail method |
131+
| `fdesc→` | focusDescribe method |
132+
| `fit→` | focusedIt method |
133+
| `pen→` | pending method |
134+
| `ssp→` | setSpecProperty method |
135+
| `ssup→` | setSuiteProperty method |
136+
| `so→` | spyOn method |
137+
| `soaf→` | spyOnAllFunctions method |
138+
| `spg→` | spyOnProperty get method |
139+
| `sps→` | spyOnProperty set method |
140+
| `xdesc→` | xDescribe method |
141+
| `xit→` | xIt method |
142+
| `xait→` | xItAsync method |
42143

43-
### Expectations
44-
| Trigger | Content |
45-
| -------: | ------- |
46-
| `exp→` | expect |
47-
| `tb→` | expect().toBe |
48-
| `tbct→` | expect().toBeCloseTo |
49-
| `tbd→` | expect().toBeDefined |
50-
| `tbf→` | expect().toBeFalsy |
51-
| `tbgt→` | expect().toBeGreaterThan |
52-
| `tblt→` | expect().toBeLessThan |
53-
| `tbn→` | expect().toBeNull |
54-
| `tbt→` | expect().toBeTruthy |
55-
| `tbu→` | expect().toBeUndefined |
56-
| `tc→` | expect().toContain |
57-
| `te→` | expect().toEqual |
58-
| `thbc→` | expect().toHaveBeenCalled |
59-
| `thbcw→` | expect().toHaveBeenCalledWith |
60-
| `tm→` | expect().toMatch |
61-
| `tt→` | expect().toThrow |
62-
| `tte→` | expect().toThrowError |
63-
| `nb→` | expect().not.toBe |
64-
| `nct→` | expect().not.toBeCloseTo |
65-
| `nd→` | expect().not.toBeDefined |
66-
| `nf→` | expect().not.toBeFalsy |
67-
| `ngt→` | expect().not.toBeGreaterThan |
68-
| `nlt→` | expect().not.toBeLessThan |
69-
| `nn→` | expect().not.toBeNull |
70-
| `nt→` | expect().not.toBeTruthy |
71-
| `nu→` | expect().not.toBeUndefined |
72-
| `nc→` | expect().not.toContain |
73-
| `ne→` | expect().not.toEqual |
74-
| `nm→` | expect().not.toMatch |
75-
| `nt→` | expect().not.toThrow |
76-
| `any→` | jasmine.any |
77-
| `oc→` | jasmine.objectContaining |
144+
### mocha commands
78145

79-
### Spies
80-
| Trigger | Content |
81-
| -------: | ------- |
82-
|`so→` | spyOn |
83-
|`sct→` | spyOn.and.callThrough |
84-
|`scf→` | spyOn.and.callFake |
85-
|`spg→` | spyOnProperty($obj,'$property', 'get') |
86-
|`sps→` | spyOnProperty($obj,'$property', 'set') |
87-
|`srv→` | spyOn.and.returnValue |
88-
|`ss→` | spyOn.and.stub |
89-
|`ste→` | spyOn.and.throwError |
90-
|`ca→` | spy.calls.all |
91-
|`caa→` | spy.calls.allArgs |
92-
|`ca→` | spy.calls.any |
93-
|`caf→` | spy.calls.argsFor |
94-
|`cc→` | spy.calls.count |
95-
|`cf→` | spy.calls.first |
96-
|`cmr→` | spy.calls.mostRecent |
97-
|`cr→` | spy.calls.reset |
98-
|`cs→` | createSpy |
99-
|`cso→` | createSpyObj |
146+
| Trigger | Content |
147+
| -------: | ------- |
148+
| `aa→` | afterAll method |
149+
| `aaa→` | afterAllAsync method |
150+
| `ae→` | afterEach method |
151+
| `aea→` | afterEachAsync method |
152+
| `ba→` | beforeAll method |
153+
| `baa→` | beforeAllAsync method |
154+
| `be→` | beforeEach method |
155+
| `bea→` | beforeEachAsync method |
156+
| `desc→` | describe method |
157+
| `it→` | it method |
158+
| `ait→` | itAsync method |
159+
| `desco→` | describeOnly method |
160+
| `descsk→` | describeSkip method |
161+
| `ito→` | itOnly method |
162+
| `itsk→` | itSkip method |
100163

101164
[jasmine]: http://jasmine.github.io
102165
[sublime-jusmine]: https://github.com/NicoSantangelo/sublime-jasmine

extension.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const vscode = require('vscode');
4+
const merge = require('lodash.merge')
5+
6+
const generic = require('./snippets/frameworks/generic.json')
7+
const jasmine = require('./snippets/frameworks/jasmine.json')
8+
const mocha = require('./snippets/frameworks/mocha.json')
9+
const jest = require('./snippets/frameworks/jest.json')
10+
11+
function activate(context) {
12+
vscode.languages.registerCompletionItemProvider(
13+
{language: 'javascript', scheme: 'file'},
14+
{
15+
provideCompletionItems(document, position, token, context) {
16+
const quote = vscode.workspace.getConfiguration('javascript-test-snippets').get('quoteStyle', '"')
17+
const framework = vscode.workspace.getConfiguration('javascript-test-snippets').get('framework', 'mocha')
18+
19+
let definedCompletions = generic
20+
21+
if (framework === 'mocha') {
22+
definedCompletions = merge(definedCompletions, mocha)
23+
} else if (framework === 'jest') {
24+
definedCompletions = merge(definedCompletions, jest)
25+
} else {
26+
definedCompletions = merge(definedCompletions, jasmine)
27+
}
28+
29+
const completions = []
30+
for (const testCompletion in definedCompletions) {
31+
let item = new vscode.CompletionItem(
32+
{
33+
label: definedCompletions[testCompletion].prefix,
34+
description: definedCompletions[testCompletion].description,
35+
},
36+
vscode.CompletionItemKind.Snippet
37+
)
38+
let insertTextOriginal = definedCompletions[testCompletion].body
39+
const newQuoteInsertText = insertTextOriginal.replaceAll("'", quote)
40+
item.insertText = new vscode.SnippetString(newQuoteInsertText)
41+
completions.push(item)
42+
}
43+
44+
return new vscode.CompletionList(completions)
45+
46+
}
47+
}
48+
)
49+
}
50+
51+
// this method is called when your extension is deactivated
52+
function deactivate() {}
53+
54+
// eslint-disable-next-line no-undef
55+
module.exports = {
56+
activate,
57+
deactivate
58+
}

images/jasmine.png

-14.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)