Skip to content

Commit cf5685c

Browse files
committed
add tests and github workflow
1 parent 7147755 commit cf5685c

File tree

12 files changed

+7879
-30
lines changed

12 files changed

+7879
-30
lines changed

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"node": true,
5+
"es6": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 6,
9+
"sourceType": "module"
10+
},
11+
"parser": "babel-eslint",
12+
"rules": {
13+
"indent": ["error", 2, { "SwitchCase": 1 }],
14+
"linebreak-style": ["error", "unix"],
15+
"no-trailing-spaces": 2,
16+
"eol-last": 2,
17+
"space-in-parens": ["error", "never"],
18+
"no-multiple-empty-lines": 1,
19+
"prefer-const": "error",
20+
"space-infix-ops": "error",
21+
"no-useless-escape": "off",
22+
"require-atomic-updates": "off",
23+
"no-var": 1,
24+
"no-await-in-loop" : 1
25+
},
26+
"globals" : {
27+
"Parse" : true
28+
}
29+
}

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Node.js
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- '**'
9+
workflow_dispatch:
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [12.x]
16+
name: ${{ matrix.name }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- name: Install Dependancies
24+
run: npm install
25+
- name: Check Linting
26+
run: npm run lint
27+
- name: Run Tests
28+
run: npm run test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ node_modules
2828

2929
# Emacs
3030
*~
31+
.eslintcache

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,14 @@ Example using it via JavaScript:
133133
Parse.initialize('myAppId','unused');
134134
Parse.serverURL = 'https://whatever.herokuapp.com';
135135

136-
var obj = new Parse.Object('GameScore');
136+
const obj = new Parse.Object('GameScore');
137137
obj.set('score',1337);
138-
obj.save().then(function(obj) {
139-
console.log(obj.toJSON());
140-
var query = new Parse.Query('GameScore');
141-
query.get(obj.id).then(function(objAgain) {
142-
console.log(objAgain.toJSON());
143-
}, function(err) {console.log(err); });
144-
}, function(err) { console.log(err); });
138+
await obj.save();
139+
console.log(obj.toJSON());
140+
141+
const query = new Parse.Query('GameScore');
142+
const objAgain = await query.get(obj.id);
143+
console.log(objAgain.toJSON());
145144
```
146145

147146
Example using it on Android:

cloud/main.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
Parse.Cloud.define('hello', function(req, res) {
1+
Parse.Cloud.define('hello', (req) => {
2+
console.log(req)
23
return 'Hi';
34
});
5+
6+
Parse.Cloud.define('asyncFunction', async (req) => {
7+
await new Promise((resolve) => setTimeout(resolve,1000));
8+
console.log(req)
9+
return 'Hi async';
10+
});
11+
12+
Parse.Cloud.beforeSave('Test', () => {
13+
throw new Parse.Error(211,'Saving test objects is not available.')
14+
});

index.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// Example express application adding the parse-server module to expose Parse
22
// compatible API routes.
33

4-
var express = require('express');
5-
var ParseServer = require('parse-server').ParseServer;
6-
var path = require('path');
4+
const express = require('express');
5+
const ParseServer = require('parse-server').ParseServer;
6+
const path = require('path');
7+
const args = process.argv || [];
8+
const test = args.some(arg => arg.includes('jasmine'));
79

8-
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
10+
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
911

1012
if (!databaseUri) {
1113
console.log('DATABASE_URI not specified, falling back to localhost.');
1214
}
13-
14-
var api = new ParseServer({
15+
const config = {
1516
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
1617
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
1718
appId: process.env.APP_ID || 'myAppId',
@@ -20,19 +21,22 @@ var api = new ParseServer({
2021
liveQuery: {
2122
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
2223
}
23-
});
24+
};
2425
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
2526
// If you wish you require them, you can set them as options in the initialization above:
2627
// javascriptKey, restAPIKey, dotNetKey, clientKey
2728

28-
var app = express();
29+
const app = express();
2930

3031
// Serve static assets from the /public folder
3132
app.use('/public', express.static(path.join(__dirname, '/public')));
3233

3334
// Serve the Parse API on the /parse URL prefix
34-
var mountPath = process.env.PARSE_MOUNT || '/parse';
35-
app.use(mountPath, api);
35+
const mountPath = process.env.PARSE_MOUNT || '/parse';
36+
if (!test) {
37+
const api = new ParseServer(config);
38+
app.use(mountPath, api);
39+
}
3640

3741
// Parse Server plays nicely with the rest of your web routes
3842
app.get('/', function(req, res) {
@@ -45,11 +49,17 @@ app.get('/test', function(req, res) {
4549
res.sendFile(path.join(__dirname, '/public/test.html'));
4650
});
4751

48-
var port = process.env.PORT || 1337;
49-
var httpServer = require('http').createServer(app);
50-
httpServer.listen(port, function() {
52+
const port = process.env.PORT || 1337;
53+
if (!test) {
54+
const httpServer = require('http').createServer(app);
55+
httpServer.listen(port, function() {
5156
console.log('parse-server-example running on port ' + port + '.');
52-
});
57+
});
58+
// This will enable the Live Query real-time server
59+
ParseServer.createLiveQueryServer(httpServer);
60+
}
5361

54-
// This will enable the Live Query real-time server
55-
ParseServer.createLiveQueryServer(httpServer);
62+
module.exports = {
63+
app,
64+
config
65+
};

0 commit comments

Comments
 (0)