-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup babel #614
base: main
Are you sure you want to change the base?
Setup babel #614
Conversation
@jywarren @sagarpreet-chadha @keshav234156 @shreyaa-sharmaa @NitinBhasneria please do check this out.
Do we need to change the es version in to |
package.json
Outdated
@@ -4,7 +4,8 @@ | |||
"description": "PublicLab.Editor is a general purpose, JavaScript/Bootstrap UI framework for rich text posting, which provides an author-friendly, minimal, mobile/desktop (fluid) interface for creating blog-like content, designed for PublicLab.org", | |||
"main": "dist/PublicLab.Editor.js", | |||
"scripts": { | |||
"build": "grunt build", | |||
"build": "grunt build && ./node_modules/.bin/babel dist -d dist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thank you @Shulammite-Aso !!!
I think perhaps we have to run grunt babel
before grunt build
or vice versa, in the travis config:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @jywarren that sounds right
will just add that now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grunt.initConfig({
babel: {
options: {
sourceMap: true,
presets: ["@babel/preset-env"],
},
dist: {
files: {
"dist/app.js": "src/app.js",
},
},
},
});
grunt.loadNpmTasks('grunt-babel');
grunt.registerTask("default", ["babel"]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to tell grunt as well that we have to use babel, more details here:
https://babeljs.io/setup#installation
package.json
Outdated
@@ -4,7 +4,8 @@ | |||
"description": "PublicLab.Editor is a general purpose, JavaScript/Bootstrap UI framework for rich text posting, which provides an author-friendly, minimal, mobile/desktop (fluid) interface for creating blog-like content, designed for PublicLab.org", | |||
"main": "dist/PublicLab.Editor.js", | |||
"scripts": { | |||
"build": "grunt build", | |||
"build": "grunt build && ./node_modules/.bin/babel dist -d dist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grunt.initConfig({
babel: {
options: {
sourceMap: true,
presets: ["@babel/preset-env"],
},
dist: {
files: {
"dist/app.js": "src/app.js",
},
},
},
});
grunt.loadNpmTasks('grunt-babel');
grunt.registerTask("default", ["babel"]);
package.json
Outdated
@@ -4,7 +4,8 @@ | |||
"description": "PublicLab.Editor is a general purpose, JavaScript/Bootstrap UI framework for rich text posting, which provides an author-friendly, minimal, mobile/desktop (fluid) interface for creating blog-like content, designed for PublicLab.org", | |||
"main": "dist/PublicLab.Editor.js", | |||
"scripts": { | |||
"build": "grunt build", | |||
"build": "grunt build && ./node_modules/.bin/babel dist -d dist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to tell grunt as well that we have to use babel, more details here:
https://babeljs.io/setup#installation
This is the grunt config file: https://github.com/publiclab/PublicLab.Editor/blob/main/Gruntfile.js |
Wait though, do the Jasmine tests run on the compiled version? I guess they do, ok... I'll accept the suggestions above to see if they work even without teaching Grunt about babel! |
script: | ||
- npm run build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm going ot try this as a before_script so we are sure it's done before it tries the tests.
OK just to review what's happening here:
I believe this is an issue with PhantomJS - that errors are read-only? https://stackoverflow.com/questions/20055368/typeerror-attempted-to-assign-to-readonly-property Hmm. The line is:
|
Aha - this occurs in strict mode! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Read-only And |
https://www.npmjs.com/package/resig-class -- can we find an alternative that works with strict mode/ES6? Used in all these files: https://github.com/publiclab/PublicLab.Editor/search?q=resig&unscoped_q=resig |
Some possible related research: https://stackoverflow.com/questions/15050816/is-john-resigs-javascript-inheritance-snippet-deprecated wow this is obscure! |
Made an issue here on the NPM module - mattinsler/resig-class#2 |
OK! I tried replacing But now get the error:
If i skip the
So, I think we may need to configure babel to not use strict mode? Ah - wait - babel can be configured for script mode and then doesn't use strict: https://stackoverflow.com/a/34983495 (if i understand this properly... 😅 ) |
OK, so i added: "sourceType": "script", to
|
Aha! I reverted the |
Fingers 🤞 !!! This has been a really deep obscure issue! Whoa!!! 🤯 |
OMG lol. Jasmine tests now run. But Jest tests fail:
Can we do this in another order? |
Wow - the folks at mattinsler/resig-class#2 just updated to v2.0.0 with a change that may make this error no longer occur. Let's try reverting the |
OK - so, we now see this again:
I think we can get past this if we turn on "script" mode in babel once more. But that will still break the Jest tests. But I think we actually do need babel to be compiling for script mode... i'm going to turn that back on and we will probably need to adjust the Jest test setup to get those running again. Sorry for the run-around here! Looks like we're back to where we were on Tuesday! |
Aha searched around for this error "Jest ReferenceError: regeneratorRuntime is not defined" - here is the issue, i think! jestjs/jest#7579 (comment)
The next comment down has another suggestion which I'll try: // babel.config.js
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
],
} |
.babelrc
Outdated
@@ -0,0 +1,4 @@ | |||
{ | |||
['@babel/preset-env', { targets: { node: 'current' } }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried this!
@jywarren sorry i've been away here. I've not been able to quickly wrap my head around what should be done next. 😄 I'm not sure if this makes any different but i see that the example here https://stackoverflow.com/a/34983495 is setting
Does this matter here? And another option is to to set |
Thanks @Shulammite-Aso -- no problem, i'm just trying to crack this tough one! I just made a syntax error so i'll fix that and see if it works. But if it doesn't, either of your two ideas are probably worth trying! And also, probably easier to iterate faster in GitPod or locally, instead of waiting for Travis to run as I'm doing 😅 |
Hmm:
|
Hmm, ok, we're back to:
@Shulammite-Aso would you like to try a few variations? |
I think it may be worth checking if we need |
Hmm -- unfortunately it doesn't look like it worked. Would anyone from the broader @publiclab/editor team want to try to get this to pass? Thanks, everyone! |
Hey, great work @Shulammite-Aso! |
I will also try this 👍 |
Duh... i realized, I gotta remember that we don't need puppeteer for the Jasmine tests, and those are the ones failing right now... will try them now in gitpod. |
OK, and noting that |
OH
|
On this line:
|
I think usage of |
I wonder if, in Jasmine, the global definition on these lines is not getting created:
Could we pre-declare them, and then the global-ness wouldn't matter? |
Trying to switch to Jasmine v2, which uses Headless Chrome, not Phantomjs, so it'll run in the same system as Jest. |
Hmm. Now, it looks like we got past the initial PL undefined error, but the constructor is not properly creating an
https://travis-ci.com/github/publiclab/PublicLab.Editor/jobs/399261338#L309 |
I don't know, folks, I'm out of energy for now... I wonder if we should just think of refactoring all the Jasmine tests into Jest??? |
For reference, it looks like Jest and Jasmine test syntax is really similar: // Jasmine:
it("exists, and has a textarea", function() {
expect($('.ple-textarea')[0]).not.toBeUndefined();
expect(editor).not.toBeUndefined();
expect(editor.options.textarea).not.toBeUndefined();
expect(editor.options.textarea).toBe($('.ple-textarea')[0]);
});
// Jest:
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
}); https://github.com/publiclab/PublicLab.Editor/blob/main/spec/javascripts/editor_spec.js |
I've refactored the |
:-////
|
Maybe this issue I faced long time back is related to this: publiclab/leaflet-blurred-location-display#52 |
Hi @Sagarpreet it's possible regarding your comment on phantomjs, but |
i think it could be related overall though - are we declaring strict mode, and perhaps our attempt within the editor library to define globals is not working because that's no longer allowed in ES6 or strict mode? |
Noting that we're seeing the |
Much progress in #680 !!! |
OK! Much of this is now solved due to the And, the original reason was that Jasmine couldn't do ES6 which is now no longer the case, so there isn't as strong a reason for this now. But Babel is nice so if anyone wants to try, go for it! |
Fixes #607
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
grunt jasmine
fixes #0000
-style reference to original issue #@publiclab/reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays.
Thanks!