Skip to content
29 changes: 17 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const FULL_HEADER = (
' */\n'
);

gulp.task('compile', function() {
return gulp.src('src/*.js')
function compileTask(stream) {
return stream
.pipe(babel({
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
Expand All @@ -76,6 +76,10 @@ gulp.task('compile', function() {
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
}

gulp.task('compile', function() {
return compileTask(gulp.src('src/*.js'));
});

gulp.task('browserify', function(cb) {
Expand Down Expand Up @@ -132,14 +136,15 @@ gulp.task('minify-weapp', function() {
});

gulp.task('watch', function() {
return watch('src/*.js', { ignoreInitial: false, verbose: true })
.pipe(babel({
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
}))
// Second pass to kill BUILD-switched code
.pipe(babel({
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
if (BUILD === 'browser') {
const watcher = gulp.watch('src/*.js', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
watcher.on('add', function(path) {
console.log(`File ${path} was added`);
});
watcher.on('change', function(path) {
console.log(`File ${path} was changed`);
});
return watcher;
}
return compileTask(watch('src/*.js', { ignoreInitial: false, verbose: true }));
});
46 changes: 44 additions & 2 deletions integration/test/ParseDistTest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const puppeteer = require('puppeteer');
const { resolvingPromise } = require('../../lib/node/promiseUtils');

let browser = null;
let page = null;
for (const fileName of ['parse.js', 'parse.min.js']) {
describe(`Parse Dist Test ${fileName}`, () => {
beforeEach(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
browser = await puppeteer.launch({ args: ['--disable-web-security'] });
const context = await browser.createIncognitoBrowserContext();
page = await context.newPage();
await page.setCacheEnabled(false);
await page.goto(`http://localhost:1337/${fileName}`);
});

Expand Down Expand Up @@ -35,5 +39,43 @@ for (const fileName of ['parse.js', 'parse.min.js']) {
expect(obj).toBeDefined();
expect(obj.id).toEqual(response);
});

it('can cancel save file with uri', async () => {
let requestsCount = 0;
let abortedCount = 0;
const promise = resolvingPromise();
await page.setRequestInterception(true);
page.on('request', request => {
if (!request.url().includes('favicon.ico')) {
requestsCount += 1;
}
request.continue();
});
page.on('requestfailed', request => {
if (request.failure().errorText === 'net::ERR_ABORTED' && !request.url().includes('favicon.ico')) {
abortedCount += 1;
promise.resolve();
}
});
await page.evaluate(async () => {
const parseLogo =
'https://raw.githubusercontent.com/parse-community/parse-server/master/.github/parse-server-logo.png';
const file = new Parse.File('parse-server-logo', { uri: parseLogo });
file.save().then(() => {});

return new Promise((resolve) => {
const intervalId = setInterval(() => {
if (file._requestTask && typeof file._requestTask.abort === 'function') {
file.cancel();
clearInterval(intervalId);
resolve();
}
}, 1);
});
});
await promise;
expect(requestsCount).toBe(1);
expect(abortedCount).toBe(1);
});
});
}
1 change: 1 addition & 0 deletions src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class ParseFile {
*/
cancel() {
if (this._requestTask && typeof this._requestTask.abort === 'function') {
this._requestTask._aborted = true;
this._requestTask.abort();
}
this._requestTask = null;
Expand Down