diff --git a/.vscode/launch.json b/.vscode/launch.json index 38041cb91..408350c5a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,7 +7,7 @@ { "type": "node", "request": "launch", - "name": "Unit Tests", + "name": "Launch mocha tests", "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "args": [ "--timeout", @@ -15,82 +15,67 @@ "--opts", "unit-tests/mocha.opts" ], - "internalConsoleOptions": "openOnSessionStart", + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", "preLaunchTask": "tsc-unit-tests" }, { - "name": "Launch on iOS", - "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", + "name": "Launch tests on Android", "type": "nativescript", "request": "launch", "platform": "android", "appRoot": "${workspaceRoot}/tests", "sourceMaps": 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", "request": "attach", "platform": "android", - "appRoot": "${workspaceRoot}", + "appRoot": "${workspaceRoot}/e2e/ui-tests-app", "sourceMaps": true, "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 } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7dc223a06..7781a38a2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,28 +1,14 @@ { - // See http://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "0.1.0", - "command": "tsc", - "isShellCommand": true, - "args": ["-p", "."], - "showOutput": "always", - "problemMatcher": "$tsc", - "tasks": [ - { - "taskName": "tsc-unit-tests", + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "tsc-unit-tests", + "type": "shell", "problemMatcher": "$tsc", "command": "./node_modules/.bin/tsc", - "args": [ "-p", "tsconfig.unit-tests.json" ] - }, - { - "taskName": "unit-tests", - "command": "npm", - "args": ["run", "unit-test"] - }, - { - "taskName": "unit-tests-watch", - "command": "npm", - "args": ["run", "unit-test-watch"] - } - ] + "args": [ "-p", "unit-tests/tsconfig.json" ], + } + ] } \ No newline at end of file diff --git a/e2e/animation/app/package.json b/e2e/animation/app/package.json index 0d6fdb754..d4e0596bc 100644 --- a/e2e/animation/app/package.json +++ b/e2e/animation/app/package.json @@ -1,6 +1,7 @@ { "android": { - "v8Flags": "--expose_gc" + "v8Flags": "--expose_gc", + "markingMode": "none" }, "main": "app.js", "name": "tns-template-hello-world-ts", diff --git a/e2e/cuteness.io/app/package.json b/e2e/cuteness.io/app/package.json index ab73df24b..7d2fc03cc 100644 --- a/e2e/cuteness.io/app/package.json +++ b/e2e/cuteness.io/app/package.json @@ -1,6 +1,7 @@ { "main": "app-page.js", "android": { - "v8Flags": "--expose_gc" + "v8Flags": "--expose_gc", + "markingMode": "none" } } diff --git a/e2e/file-qualifiers/app/package.json b/e2e/file-qualifiers/app/package.json index 3414e605f..6970ce225 100644 --- a/e2e/file-qualifiers/app/package.json +++ b/e2e/file-qualifiers/app/package.json @@ -1,6 +1,7 @@ { "android": { - "v8Flags": "--expose_gc" + "v8Flags": "--expose_gc", + "markingMode": "none" }, "main": "app.js" } \ No newline at end of file diff --git a/e2e/modal-navigation/app/package.json b/e2e/modal-navigation/app/package.json index 0d6fdb754..d4e0596bc 100644 --- a/e2e/modal-navigation/app/package.json +++ b/e2e/modal-navigation/app/package.json @@ -1,6 +1,7 @@ { "android": { - "v8Flags": "--expose_gc" + "v8Flags": "--expose_gc", + "markingMode": "none" }, "main": "app.js", "name": "tns-template-hello-world-ts", diff --git a/tests/app/package.json b/tests/app/package.json index 24cb7bc4c..c13032ce6 100644 --- a/tests/app/package.json +++ b/tests/app/package.json @@ -1,6 +1,7 @@ { "main": "app.js", "android": { - "v8Flags": "--expose_gc" + "v8Flags": "--expose_gc", + "markingMode": "none" } } diff --git a/unit-tests/css/parser.ts b/unit-tests/css/parser.ts index 530cd3192..81f6ea33f 100644 --- a/unit-tests/css/parser.ts +++ b/unit-tests/css/parser.ts @@ -11,18 +11,15 @@ import { TokenObjectType, CSSNativeScript, } from "@nativescript/core/css/parser"; -import { - parse -} from "@nativescript/core/css"; import * as fs from "fs"; -import * as shadyCss from 'shady-css-parser'; -import * as reworkCss from 'css'; +import * as shadyCss from "shady-css-parser"; +import * as reworkCss from "css"; -const parseCss: any = require('parse-css'); -const gonzales: any = require('gonzales'); +const parseCss: any = require("parse-css"); +const gonzales: any = require("gonzales"); const parserlib: any = require("parserlib"); -const csstree: any = require('css-tree'); +const csstree: any = require("css-tree"); describe("css", () => { describe("parser", () => { @@ -45,7 +42,7 @@ describe("css", () => { describe("values", () => { describe("url", () => { 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) #FF0000", 15, null); test(parseURL, "repeat url(lucky.gif) #FF0000", 6, { start: 6, end: 22, value: "lucky.gif" }); @@ -92,8 +89,8 @@ describe("css", () => { }); describe("background", () => { 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, ' url(smiley.gif) no-repeat top 50% left 100% #00ff00', { start: 0, end: 56, value: { + 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: { color: 0xFF00FF00, image: "smiley.gif", repeat: "no-repeat", @@ -103,7 +100,7 @@ describe("css", () => { 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, image: "smiley.gif", repeat: "no-repeat", @@ -114,24 +111,24 @@ describe("css", () => { }, 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: { - angle: Math.PI * 1/4, + angle: Math.PI * 1 / 4, 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: { - angle: Math.PI * 1/4, + angle: Math.PI * 1 / 4, colors: [ { argb: 0xFF0000FF }, { 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: { - angle: Math.PI * 0/4, + angle: Math.PI * 0 / 4, colors: [ { argb: 0xFF0000FF }, { argb: 0xFF008000, offset: { value: 0.4, unit: "%" }}, @@ -229,15 +226,23 @@ describe("css", () => { let original = themeCoreLightIos.replace(/\/\*([^\/]|\/[^\*])*\*\//g, "").replace(/\n/g, " "); let roundtrip = stylesheet.map(m => { - if (!m) return ""; - if (typeof m === "string") return m; + if (!m) { + return ""; + } + + if (typeof m === "string") { + return m; + } + return m.text; }).join(""); let lastIndex = Math.min(original.length, roundtrip.length); - for(var i = 0; i < lastIndex; i++) - if (original[i] != roundtrip[i]) + for (var i = 0; i < lastIndex; 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.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 stylesheet = parser.parseAStylesheet(); - assert.deepEqual(stylesheet, {rules:[ + assert.deepEqual(stylesheet, {rules: [ { type: "qualified-rule", prelude: [{ type: 2, text: "." }, { type: 6, text: "btn-primary" }], @@ -370,6 +375,7 @@ describe("css", () => { const [startSec, startMSec] = process.hrtime(); action(); const [endSec, endMSec] = process.hrtime(); + return (endSec - startSec) * 1000 + (endMSec - startMSec) / 1000000; } const charCodeByCharCodeDuration = trapDuration(() => { @@ -390,7 +396,7 @@ describe("css", () => { let char; let c = 0; 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 === "_") { c++; } @@ -402,7 +408,7 @@ describe("css", () => { let char; let c = 0; for (let i = 0; i < themeCoreLightIos.length; i++) { - const char = themeCoreLightIos[i]; + char = themeCoreLightIos[i]; if (compareCharRegEx.test(char)) { c++; } diff --git a/unit-tests/ui/styling/css-selector.ts b/unit-tests/ui/styling/css-selector.ts index f20f7792f..8d400a200 100644 --- a/unit-tests/ui/styling/css-selector.ts +++ b/unit-tests/ui/styling/css-selector.ts @@ -22,12 +22,14 @@ describe("ui", () => { let rulesAst = parse.stylesheet.rules.filter(n => n.type === "rule"); let rules = selector.fromAstNodes(rulesAst); let map = new selector.SelectorsMap(rules); + return { rules, map }; } function createOne(css: string, source: string = "css-selectors.ts@test"): selector.RuleSet { let {rules} = create(css, source); assert.equal(rules.length, 1); + return rules[0]; } @@ -51,7 +53,7 @@ describe("ui", () => { button { color: red; } image { color: green; } `); - + let buttonQuerry = map.query({ cssType: "button" }).selectors; assert.equal(buttonQuerry.length, 1); assert.includeDeepMembers(buttonQuerry[0].ruleset.declarations, [ @@ -76,8 +78,8 @@ describe("ui", () => { ".class": (view) => view.cssClasses.has("class"), ":pseudo": (view) => view.cssPseudoClasses.has("pseudo"), "[src1]": (view) => "src1" in view, - "[src2='src-value']": (view) => view['src2'] === 'src-value' - } + "[src2='src-value']": (view) => view["src2"] === "src-value" + }; let positivelyMatchingView = { cssType: "type", @@ -86,7 +88,7 @@ describe("ui", () => { cssPseudoClasses: new Set(["pseudo"]), "src1": "src", "src2": "src-value" - } + }; let negativelyMatchingView = { cssType: "nottype", @@ -95,7 +97,7 @@ describe("ui", () => { cssPseudoClasses: new Set(["notpseudo"]), // Has no "src1" "src2": "not-src-value" - } + }; it("simple selectors match", () => { for (let sel in positiveMatches) { @@ -191,7 +193,8 @@ describe("ui", () => { } } } - } + }; + assert.isTrue(sel.match(child)); }); @@ -215,7 +218,7 @@ describe("ui", () => { toString } } - } + }; let match = map.query(button); assert.equal(match.selectors.length, 1, "Expected match to have one selector.");