Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit a9c8a3d

Browse files
committed
Add a CONTRIBUTING.md to repository.
1 parent d0b9353 commit a9c8a3d

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

CONTRIBUTING.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Contributing to sqlite-parser
2+
3+
Thank you for your interest in contributing! This guide explains the flow for
4+
making contributions to this repository.
5+
6+
## Demo
7+
8+
You can run a copy of the parser's interactive demo on your local machine
9+
(at `http://localhost:8080/`) by cloning this repository and then using the
10+
command `grunt live`.
11+
12+
## Getting started
13+
14+
After cloning the repository, run `npm install` to install the development
15+
dependencies. Once the dependencies are installed, start development with the
16+
following command:
17+
18+
```
19+
grunt testwatch
20+
```
21+
22+
which will automatically compile the parser and run the tests in each time a
23+
change is made to the tests and/or the source code.
24+
25+
Optionally, run `grunt debug` to write the ASTs from each to test to `stdout` in
26+
addition to live reloading.
27+
28+
## Writing tests
29+
30+
Each test refers to a SQL input file in `test/sql/` and an expected output
31+
JSON AST file.
32+
33+
For example a `describe()` block with the title `parent block` that contains an
34+
`it()` block named `super test 2` will look for the SQL input at
35+
`test/sql/parent-block/super-test-2.sql` and the JSON AST at
36+
`test/json/parent-block/super-test-2.json`.
37+
38+
There are three options for the test helpers exposed by `tree`:
39+
- Assert that the test file successfully generates _any_ valid AST
40+
``` javascript
41+
tree.ok(this, done);
42+
```
43+
44+
- Assert that the test file generates an AST that exactly matches the expected output JSON file
45+
``` javascript
46+
tree.equals(this, done);
47+
```
48+
49+
- Assert that a test throws an error
50+
- Assert that any error was thrown
51+
``` javascript
52+
tree.error({}, this, done);
53+
```
54+
55+
- Assert a specific error `message` for the thrown error
56+
``` javascript
57+
tree.error('My error message.', this, done);
58+
```
59+
60+
- Assert an object of properties that all exist in the thrown error object
61+
``` javascript
62+
tree.error({
63+
message: 'You forgot to add a boop to the beep.',
64+
location: {
65+
start: { offset: 0, line: 1, column: 1 },
66+
end: { offset: 0, line: 1, column: 1 }
67+
}
68+
}, this, done)
69+
```
70+
71+
``` javascript
72+
/* All the helper functions in `/test/helpers.js` are already available
73+
* and do not need to be explicitly imported.
74+
*/
75+
describe('select', function () {
76+
/* Test SQL: test/sql/select/basic-select.sql
77+
* Expected JSON AST: test/json/select/basic-select.json
78+
*/
79+
it('basic select', function (done) {
80+
tree.equals(this, done);
81+
});
82+
});
83+
84+
describe('parse errors', function (done) {
85+
/* Test SQL: test/sql/parse-errors/parse-error-1.sql
86+
* Expected JSON AST: test/json/parse-errors/parse-error-1.json
87+
*/
88+
it('parse error 1', function(done) {
89+
tree.error({
90+
'message': 'Syntax error found near Column Identifier (WHERE Clause)'
91+
}, this, done);
92+
});
93+
});
94+
```
95+
96+
## Submitting a PR
97+
98+
**Do not** change the version number in the `package.json` within a pull
99+
request submitted to this repository.
100+
101+
The last step before committing your changes and creating the pull request is
102+
to run the release command and stage any changes that are generated:
103+
104+
```
105+
grunt release
106+
```
107+
108+
## Available development commands
109+
110+
- Create new build of the parser in `.tmp/` folder
111+
```
112+
grunt build
113+
```
114+
115+
- Create new `lib/` folder containing the release version of the parser
116+
```
117+
grunt dist
118+
```
119+
120+
- Create new version of command line utility at `bin/sqlite-parser`
121+
```
122+
grunt bin
123+
```
124+
125+
- Build parser to `.tmp/` and run tests
126+
```
127+
grunt test
128+
```
129+
130+
- Build parser to `.tmp/` and run extended test suite
131+
```
132+
grunt testall
133+
```
134+
135+
- Watch the parser and then build to `.tmp/` and run tests on changes
136+
```
137+
grunt testwatch
138+
```
139+
140+
- Is `testwatch` but also logs the generated ASTs as formatted JSON objects in the test output
141+
```
142+
grunt debug
143+
```
144+
145+
- Build the parser to `.tmp/` and run tests, but take the output from the parser use it to overwrite the existing test JSON files in `test/json/`
146+
```
147+
grunt rewritejson
148+
```
149+
150+
- Rebuild the interactive demo site to `.tmp/`
151+
```
152+
grunt interactive
153+
```
154+
155+
- Watch the parser and demo files and then build parser and interactive demo to `.tmp/` on changes
156+
```
157+
grunt live
158+
```
159+
160+
- Build the interactive demo as a `index.html` and one minified CSS and one minified JS bundle to the `demo/` folder
161+
```
162+
grunt demo
163+
```
164+
165+
- Create new command line parser at `bin/sqlite-parser`, create release version of the parser in `lib/` and then create a new copy of the release version of the interactive demo in `demo/`
166+
```
167+
grunt release
168+
```

0 commit comments

Comments
 (0)