-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: added tests/typescript
to test supported TS examples
#6775
Conversation
cdd9888
to
464f700
Compare
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.
Yay for more tests!
.eslintignore
Outdated
@@ -11,6 +11,7 @@ | |||
/tests/screenshot/* | |||
/tests/test_runner.js | |||
/tests/workspace_svg/* | |||
/tests/typescript/* |
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.
How much work would it be to get the new tests to lint cleanly?
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 not sure how straightforward it will be, though I'll look further into it this upcoming Friday. And get back to you when I've looked into it a bit more.
The configuration in .eslintrc.json
points to the root ./tsconfig.json
via parserOptions
which I believe was the main issue, though there may be around that. These tests need their own tsconfig so they aren't built and packaged with the rest of the code.
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.
Updated! The tsconfig is defined in an array, which I hadn't noticed at my quick glance earlier, so I just had to add the second override.
Of note, I updated .eslintrc.json
to .eslintrc.js
since we likely want the same settings for the overrides, and it's easier to keep them in sync via JS than in JSON.
Should be all set! Please check my changes which update
|
e4085f2
to
879bfd5
Compare
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.
In addition to changing the tsc
output directory (see below), can you update .eslintrc.js
to follow the JS style guide, please? E.g.:
- Indentation by two spaces.
- Use single quotes for strings, no quoting of property names that are valid identifieres,
- Ends with
\n
.
You can probably just run clang-format
on it. Better: modify the config so that this file is always formatted when npm run format
is run.
scripts/gulpfiles/test_tasks.js
Outdated
*/ | ||
function typeDefinitions() { | ||
return runTestCommand('type_definitions', | ||
'tsc -p ./tests/typescript/tsconfig.json'); |
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.
Please write output to somewhere in build/
rather than in tests/
.
I think it would be preferable to do so using -outDir
and path.join(BUILD_DIR, 'tests' /* optionally more */)
as buildJavaScript
(in build_tasks.js
) does.
.eslintignore
Outdated
@@ -11,6 +11,7 @@ | |||
/tests/screenshot/* | |||
/tests/test_runner.js | |||
/tests/workspace_svg/* | |||
/tests/typescript/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 should not be necessary.
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.
When this is not ignored, I get an error like below:
5:1 error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
Basically it's trying to run lint on the JS files that are created in /tests/typescript/dist
879bfd5
to
19f0a55
Compare
.eslintrc.js
Outdated
'extends' : | ||
[ | ||
'eslint:recommended', | ||
'google', | ||
], |
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.
Go home formatter, you're drunk:
'extends' : | |
[ | |
'eslint:recommended', | |
'google', | |
], | |
extends: [ | |
'eslint:recommended', | |
'google', | |
], |
(and similarly for overrides
.)
@@ -0,0 +1,215 @@ | |||
const rules = { | |||
'curly': ['error'], |
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.
Single quotes not required for property names that are valid identifiers:
'curly': ['error'], | |
curly: ['error'], |
(and many below).
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.
done
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.
Looks like the linter wants consistently quoted properties. In TypeScript, it's best practice to quote keys you don't know at compile time. For example:
interface Test {
knownKey: string;
[key: string]: number;
}
const test: Test = {
knownKey: 'value',
'unknownOne': 1,
'unknownTwo': 2
};
With that principle in mind, maybe it's valid to keep the keys that are defined by eslint outside of this file quoted.
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.
In TypeScript, it's best practice to quote keys you don't know at compile time.
TIL. Though I'm not sure that argument is exactly applicable here, since I'd guess that the format of the tsconfig data structure is probably fully defined somewhere in the tsc
source code.
scripts/gulpfiles/config.js
Outdated
// Directory where typescript compiler can be found for `./tests/typescript` | ||
// files. |
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 description seems confusing to me. How about:
// Directory where typescript compiler can be found for `./tests/typescript` | |
// files. | |
// Directory for files generated by compiling test code. |
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.
done
0e93012
to
92d4dd8
Compare
@@ -0,0 +1,215 @@ | |||
const rules = { | |||
'curly': ['error'], |
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.
In TypeScript, it's best practice to quote keys you don't know at compile time.
TIL. Though I'm not sure that argument is exactly applicable here, since I'd guess that the format of the tsconfig data structure is probably fully defined somewhere in the tsc
source code.
The basics
npm run format
andnpm run lint
The details
Resolves
This adds support for testing theoretical Blockly use cases, as mentioned in #6639 (review)
Proposed Changes
Updated
npm run test
to include a new suite of tests connected totests/typescript
:tsc
command displays in the console output.Behavior Before Change
One less test suite to run.
Behavior After Change
One more test suite to run.
Reason for Changes
To enable testing fake custom fields. This allows us to see how core updates impact use cases we'd like to support.
Test Coverage
N/A
Documentation
I don't believe so.
Additional Information
core/field.ts
value functions #6639 about allowingField
subclasses to have different type information for what's passed intosetValue
than is stored on theField
.npm run test
, verifying it passes when the command passes, fails when the command fails, and properly outputs the log info needed to debug the failure.