chore: housekeeping (#8129)

This commit is contained in:
Manol Donev
2019-11-21 16:51:17 +02:00
committed by GitHub
parent 8d2dd2eb21
commit 0175c4b35a
9 changed files with 107 additions and 122 deletions

107
.vscode/launch.json vendored
View File

@ -7,7 +7,7 @@
{ {
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Unit Tests", "name": "Launch mocha tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [ "args": [
"--timeout", "--timeout",
@ -15,82 +15,67 @@
"--opts", "--opts",
"unit-tests/mocha.opts" "unit-tests/mocha.opts"
], ],
"internalConsoleOptions": "openOnSessionStart", "console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "tsc-unit-tests" "preLaunchTask": "tsc-unit-tests"
}, },
{ {
"name": "Launch on iOS", "name": "Launch tests on Android",
"type": "nativescript",
"request": "launch",
"platform": "ios",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": true
},
// {
// "name": "Test on iOS",
// "type": "nativescript",
// "request": "launch",
// "platform": "ios",
// "appRoot": "${workspaceRoot}",
// "sourceMaps": true,
// "watch": false,
// "stopOnEntry": true,
// "launchTests": true,
// "tnsArgs": [
// "--justlaunch"
// ]
// },
{
"name": "Attach on iOS",
"type": "nativescript",
"request": "attach",
"platform": "ios",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": false
},
{
"name": "Launch on Android",
"type": "nativescript",
"request": "launch",
"platform": "android",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": true
},
{
"name": "Debug tests on Android",
"type": "nativescript", "type": "nativescript",
"request": "launch", "request": "launch",
"platform": "android", "platform": "android",
"appRoot": "${workspaceRoot}/tests", "appRoot": "${workspaceRoot}/tests",
"sourceMaps": true, "sourceMaps": true,
"stopOnEntry": true, "stopOnEntry": true,
"watch": true, "watch": true
}, },
// {
// "name": "Test on Android",
// "type": "nativescript",
// "request": "launch",
// "platform": "android",
// "appRoot": "${workspaceRoot}",
// "sourceMaps": true,
// "watch": false,
// "stopOnEntry": true,
// "launchTests": true,
// "tnsArgs": [
// "--justlaunch"
// ]
// },
{ {
"name": "Attach on Android", "name": "Launch tests on iOS",
"type": "nativescript",
"request": "launch",
"platform": "ios",
"appRoot": "${workspaceRoot}/tests",
"sourceMaps": true,
"stopOnEntry": true,
"watch": true
},
{
"name": "Attach ui tests on Android",
"type": "nativescript", "type": "nativescript",
"request": "attach", "request": "attach",
"platform": "android", "platform": "android",
"appRoot": "${workspaceRoot}", "appRoot": "${workspaceRoot}/e2e/ui-tests-app",
"sourceMaps": true, "sourceMaps": true,
"watch": false "watch": false
},
{
"name": "Launch ui tests on Android",
"type": "nativescript",
"request": "launch",
"platform": "android",
"appRoot": "${workspaceRoot}/e2e/ui-tests-app",
"sourceMaps": true,
"stopOnEntry": true,
"watch": true
},
{
"name": "Attach ui tests on iOS",
"type": "nativescript",
"request": "attach",
"platform": "ios",
"appRoot": "${workspaceRoot}/e2e/ui-tests-app",
"sourceMaps": true,
"watch": false
},
{
"name": "Launch ui tests on iOS",
"type": "nativescript",
"request": "launch",
"platform": "ios",
"appRoot": "${workspaceRoot}/e2e/ui-tests-app",
"sourceMaps": true,
"stopOnEntry": true,
"watch": true
} }
] ]
} }

34
.vscode/tasks.json vendored
View File

@ -1,28 +1,14 @@
{ {
// See http://go.microsoft.com/fwlink/?LinkId=733558 // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "0.1.0", "version": "2.0.0",
"command": "tsc", "tasks": [
"isShellCommand": true, {
"args": ["-p", "."], "label": "tsc-unit-tests",
"showOutput": "always", "type": "shell",
"problemMatcher": "$tsc",
"tasks": [
{
"taskName": "tsc-unit-tests",
"problemMatcher": "$tsc", "problemMatcher": "$tsc",
"command": "./node_modules/.bin/tsc", "command": "./node_modules/.bin/tsc",
"args": [ "-p", "tsconfig.unit-tests.json" ] "args": [ "-p", "unit-tests/tsconfig.json" ],
}, }
{ ]
"taskName": "unit-tests",
"command": "npm",
"args": ["run", "unit-test"]
},
{
"taskName": "unit-tests-watch",
"command": "npm",
"args": ["run", "unit-test-watch"]
}
]
} }

View File

@ -1,6 +1,7 @@
{ {
"android": { "android": {
"v8Flags": "--expose_gc" "v8Flags": "--expose_gc",
"markingMode": "none"
}, },
"main": "app.js", "main": "app.js",
"name": "tns-template-hello-world-ts", "name": "tns-template-hello-world-ts",

View File

@ -1,6 +1,7 @@
{ {
"main": "app-page.js", "main": "app-page.js",
"android": { "android": {
"v8Flags": "--expose_gc" "v8Flags": "--expose_gc",
"markingMode": "none"
} }
} }

View File

@ -1,6 +1,7 @@
{ {
"android": { "android": {
"v8Flags": "--expose_gc" "v8Flags": "--expose_gc",
"markingMode": "none"
}, },
"main": "app.js" "main": "app.js"
} }

View File

@ -1,6 +1,7 @@
{ {
"android": { "android": {
"v8Flags": "--expose_gc" "v8Flags": "--expose_gc",
"markingMode": "none"
}, },
"main": "app.js", "main": "app.js",
"name": "tns-template-hello-world-ts", "name": "tns-template-hello-world-ts",

View File

@ -1,6 +1,7 @@
{ {
"main": "app.js", "main": "app.js",
"android": { "android": {
"v8Flags": "--expose_gc" "v8Flags": "--expose_gc",
"markingMode": "none"
} }
} }

View File

@ -11,18 +11,15 @@ import {
TokenObjectType, TokenObjectType,
CSSNativeScript, CSSNativeScript,
} from "@nativescript/core/css/parser"; } from "@nativescript/core/css/parser";
import {
parse
} from "@nativescript/core/css";
import * as fs from "fs"; import * as fs from "fs";
import * as shadyCss from 'shady-css-parser'; import * as shadyCss from "shady-css-parser";
import * as reworkCss from 'css'; import * as reworkCss from "css";
const parseCss: any = require('parse-css'); const parseCss: any = require("parse-css");
const gonzales: any = require('gonzales'); const gonzales: any = require("gonzales");
const parserlib: any = require("parserlib"); const parserlib: any = require("parserlib");
const csstree: any = require('css-tree'); const csstree: any = require("css-tree");
describe("css", () => { describe("css", () => {
describe("parser", () => { describe("parser", () => {
@ -45,7 +42,7 @@ describe("css", () => {
describe("values", () => { describe("values", () => {
describe("url", () => { describe("url", () => {
test(parseURL, "url('smiley.gif') ", { start: 0, end: 19, value: "smiley.gif" }); test(parseURL, "url('smiley.gif') ", { start: 0, end: 19, value: "smiley.gif" });
test(parseURL, ' url("frown.gif") ', { start: 0, end: 19, value: "frown.gif" }); test(parseURL, " url(\"frown.gif\") ", { start: 0, end: 19, value: "frown.gif" });
test(parseURL, " url(lucky.gif)", { start: 0, end: 16, value: "lucky.gif" }); test(parseURL, " url(lucky.gif)", { start: 0, end: 16, value: "lucky.gif" });
test(parseURL, "url(lucky.gif) #FF0000", 15, null); test(parseURL, "url(lucky.gif) #FF0000", 15, null);
test(parseURL, "repeat url(lucky.gif) #FF0000", 6, { start: 6, end: 22, value: "lucky.gif" }); test(parseURL, "repeat url(lucky.gif) #FF0000", 6, { start: 6, end: 22, value: "lucky.gif" });
@ -92,8 +89,8 @@ describe("css", () => {
}); });
describe("background", () => { describe("background", () => {
test(parseBackground, " #996633 ", { start: 0, end: 12, value: { color: 0xFF996633 }}); test(parseBackground, " #996633 ", { start: 0, end: 12, value: { color: 0xFF996633 }});
test(parseBackground, ' #00ff00 url("smiley.gif") repeat-y ', { start: 0, end: 37, value: { color: 0xFF00FF00, image: "smiley.gif", repeat: "repeat-y" }}); test(parseBackground, " #00ff00 url(\"smiley.gif\") repeat-y ", { start: 0, end: 37, value: { color: 0xFF00FF00, image: "smiley.gif", repeat: "repeat-y" }});
test(parseBackground, ' url(smiley.gif) no-repeat top 50% left 100% #00ff00', { start: 0, end: 56, value: { test(parseBackground, " url(smiley.gif) no-repeat top 50% left 100% #00ff00", { start: 0, end: 56, value: {
color: 0xFF00FF00, color: 0xFF00FF00,
image: "smiley.gif", image: "smiley.gif",
repeat: "no-repeat", repeat: "no-repeat",
@ -103,7 +100,7 @@ describe("css", () => {
y: { align: "top", offset: { value: 0.5, unit: "%" }} y: { align: "top", offset: { value: 0.5, unit: "%" }}
} }
}}); }});
test(parseBackground, ' url(smiley.gif) no-repeat top 50% left 100% / 100px 100px #00ff00', { start: 0, end: 70, value: { test(parseBackground, " url(smiley.gif) no-repeat top 50% left 100% / 100px 100px #00ff00", { start: 0, end: 70, value: {
color: 0xFF00FF00, color: 0xFF00FF00,
image: "smiley.gif", image: "smiley.gif",
repeat: "no-repeat", repeat: "no-repeat",
@ -114,24 +111,24 @@ describe("css", () => {
}, },
size: { x: { value: 100, unit: "px" }, y: { value: 100, unit: "px" }} size: { x: { value: 100, unit: "px" }, y: { value: 100, unit: "px" }}
}}); }});
test(parseBackground, ' linear-gradient(to right top) ', { start: 0, end: 32, value: { test(parseBackground, " linear-gradient(to right top) ", { start: 0, end: 32, value: {
image: { image: {
angle: Math.PI * 1/4, angle: Math.PI * 1 / 4,
colors: [] colors: []
} }
}}); }});
test(parseBackground, ' linear-gradient(45deg, #0000FF, #00FF00) ', { start: 0, end: 43, value: { test(parseBackground, " linear-gradient(45deg, #0000FF, #00FF00) ", { start: 0, end: 43, value: {
image: { image: {
angle: Math.PI * 1/4, angle: Math.PI * 1 / 4,
colors: [ colors: [
{ argb: 0xFF0000FF }, { argb: 0xFF0000FF },
{ argb: 0xFF00FF00 } { argb: 0xFF00FF00 }
] ]
} }
}}); }});
test(parseBackground, 'linear-gradient(0deg, blue, green 40%, red)', { start: 0, end: 43, value: { test(parseBackground, "linear-gradient(0deg, blue, green 40%, red)", { start: 0, end: 43, value: {
image: { image: {
angle: Math.PI * 0/4, angle: Math.PI * 0 / 4,
colors: [ colors: [
{ argb: 0xFF0000FF }, { argb: 0xFF0000FF },
{ argb: 0xFF008000, offset: { value: 0.4, unit: "%" }}, { argb: 0xFF008000, offset: { value: 0.4, unit: "%" }},
@ -229,15 +226,23 @@ describe("css", () => {
let original = themeCoreLightIos.replace(/\/\*([^\/]|\/[^\*])*\*\//g, "").replace(/\n/g, " "); let original = themeCoreLightIos.replace(/\/\*([^\/]|\/[^\*])*\*\//g, "").replace(/\n/g, " ");
let roundtrip = stylesheet.map(m => { let roundtrip = stylesheet.map(m => {
if (!m) return ""; if (!m) {
if (typeof m === "string") return m; return "";
}
if (typeof m === "string") {
return m;
}
return m.text; return m.text;
}).join(""); }).join("");
let lastIndex = Math.min(original.length, roundtrip.length); let lastIndex = Math.min(original.length, roundtrip.length);
for(var i = 0; i < lastIndex; i++) for (var i = 0; i < lastIndex; i++) {
if (original[i] != roundtrip[i]) if (original[i] !== roundtrip[i]) {
assert.equal(roundtrip.substr(i, 50), original.substr(i, 50), "Round-tripped CSS string differ at index: " + i); assert.equal(roundtrip.substr(i, 50), original.substr(i, 50), "Round-tripped CSS string differ at index: " + i);
}
}
assert.equal(roundtrip.length, original.length, "Expected round-tripped string lengths to match."); assert.equal(roundtrip.length, original.length, "Expected round-tripped string lengths to match.");
}); });
@ -319,7 +324,7 @@ describe("css", () => {
const parser = new CSS3Parser(".btn-primary{border-color:rgba(255,0,0,0)}"); const parser = new CSS3Parser(".btn-primary{border-color:rgba(255,0,0,0)}");
const stylesheet = parser.parseAStylesheet(); const stylesheet = parser.parseAStylesheet();
assert.deepEqual(stylesheet, {rules:[ assert.deepEqual(stylesheet, {rules: [
{ {
type: "qualified-rule", type: "qualified-rule",
prelude: [{ type: 2, text: "." }, { type: 6, text: "btn-primary" }], prelude: [{ type: 2, text: "." }, { type: 6, text: "btn-primary" }],
@ -370,6 +375,7 @@ describe("css", () => {
const [startSec, startMSec] = process.hrtime(); const [startSec, startMSec] = process.hrtime();
action(); action();
const [endSec, endMSec] = process.hrtime(); const [endSec, endMSec] = process.hrtime();
return (endSec - startSec) * 1000 + (endMSec - startMSec) / 1000000; return (endSec - startSec) * 1000 + (endMSec - startMSec) / 1000000;
} }
const charCodeByCharCodeDuration = trapDuration(() => { const charCodeByCharCodeDuration = trapDuration(() => {
@ -390,7 +396,7 @@ describe("css", () => {
let char; let char;
let c = 0; let c = 0;
for (let i = 0; i < themeCoreLightIos.length; i++) { for (let i = 0; i < themeCoreLightIos.length; i++) {
const char = themeCoreLightIos[i]; char = themeCoreLightIos[i];
if ((char >= "a" && char <= "z") || (char >= "A" && char <= "Z") || char === "_") { if ((char >= "a" && char <= "z") || (char >= "A" && char <= "Z") || char === "_") {
c++; c++;
} }
@ -402,7 +408,7 @@ describe("css", () => {
let char; let char;
let c = 0; let c = 0;
for (let i = 0; i < themeCoreLightIos.length; i++) { for (let i = 0; i < themeCoreLightIos.length; i++) {
const char = themeCoreLightIos[i]; char = themeCoreLightIos[i];
if (compareCharRegEx.test(char)) { if (compareCharRegEx.test(char)) {
c++; c++;
} }

View File

@ -22,12 +22,14 @@ describe("ui", () => {
let rulesAst = parse.stylesheet.rules.filter(n => n.type === "rule"); let rulesAst = parse.stylesheet.rules.filter(n => n.type === "rule");
let rules = selector.fromAstNodes(rulesAst); let rules = selector.fromAstNodes(rulesAst);
let map = new selector.SelectorsMap(rules); let map = new selector.SelectorsMap(rules);
return { rules, map }; return { rules, map };
} }
function createOne(css: string, source: string = "css-selectors.ts@test"): selector.RuleSet { function createOne(css: string, source: string = "css-selectors.ts@test"): selector.RuleSet {
let {rules} = create(css, source); let {rules} = create(css, source);
assert.equal(rules.length, 1); assert.equal(rules.length, 1);
return rules[0]; return rules[0];
} }
@ -76,8 +78,8 @@ describe("ui", () => {
".class": (view) => view.cssClasses.has("class"), ".class": (view) => view.cssClasses.has("class"),
":pseudo": (view) => view.cssPseudoClasses.has("pseudo"), ":pseudo": (view) => view.cssPseudoClasses.has("pseudo"),
"[src1]": (view) => "src1" in view, "[src1]": (view) => "src1" in view,
"[src2='src-value']": (view) => view['src2'] === 'src-value' "[src2='src-value']": (view) => view["src2"] === "src-value"
} };
let positivelyMatchingView = { let positivelyMatchingView = {
cssType: "type", cssType: "type",
@ -86,7 +88,7 @@ describe("ui", () => {
cssPseudoClasses: new Set(["pseudo"]), cssPseudoClasses: new Set(["pseudo"]),
"src1": "src", "src1": "src",
"src2": "src-value" "src2": "src-value"
} };
let negativelyMatchingView = { let negativelyMatchingView = {
cssType: "nottype", cssType: "nottype",
@ -95,7 +97,7 @@ describe("ui", () => {
cssPseudoClasses: new Set(["notpseudo"]), cssPseudoClasses: new Set(["notpseudo"]),
// Has no "src1" // Has no "src1"
"src2": "not-src-value" "src2": "not-src-value"
} };
it("simple selectors match", () => { it("simple selectors match", () => {
for (let sel in positiveMatches) { for (let sel in positiveMatches) {
@ -191,7 +193,8 @@ describe("ui", () => {
} }
} }
} }
} };
assert.isTrue(sel.match(child)); assert.isTrue(sel.match(child));
}); });
@ -215,7 +218,7 @@ describe("ui", () => {
toString toString
} }
} }
} };
let match = map.query(button); let match = map.query(button);
assert.equal(match.selectors.length, 1, "Expected match to have one selector."); assert.equal(match.selectors.length, 1, "Expected match to have one selector.");