Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8FA73200CBD for ; Wed, 21 Jun 2017 22:54:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8CD63160BD5; Wed, 21 Jun 2017 20:54:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A843C160BF0 for ; Wed, 21 Jun 2017 22:54:04 +0200 (CEST) Received: (qmail 67224 invoked by uid 500); 21 Jun 2017 20:54:03 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 67095 invoked by uid 99); 21 Jun 2017 20:54:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jun 2017 20:54:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 1FFCFC061E for ; Wed, 21 Jun 2017 20:54:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Z7wxXsCsWQuw for ; Wed, 21 Jun 2017 20:54:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id D16B85F6C0 for ; Wed, 21 Jun 2017 20:54:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 67841E099E for ; Wed, 21 Jun 2017 20:54:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 24A4921942 for ; Wed, 21 Jun 2017 20:54:00 +0000 (UTC) Date: Wed, 21 Jun 2017 20:54:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CB-12361) Speed up cordova-lib tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 21 Jun 2017 20:54:05 -0000 [ https://issues.apache.org/jira/browse/CB-12361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16058207#comment-16058207 ] ASF GitHub Bot commented on CB-12361: ------------------------------------- Github user filmaj commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/567#discussion_r123362714 --- Diff: spec-cordova/prepare.spec.js --- @@ -17,175 +17,265 @@ under the License. */ -var shell = require('shelljs'), - PlatformJson = require('cordova-common').PlatformJson, - path = require('path'), - util = require('../src/cordova/util'), - prepare = require('../src/cordova/prepare'), - lazy_load = require('../src/cordova/lazy_load'), - ConfigParser = require('cordova-common').ConfigParser, - platforms = require('../src/platforms/platforms'), - HooksRunner = require('../src/hooks/HooksRunner'), - xmlHelpers = require('cordova-common').xmlHelpers, - et = require('elementtree'), - Q = require('q'); +/* eslint-env jasmine */ -var project_dir = '/some/path'; -var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; }); - -var TEST_XML = '\n' + - '\n' + - ' Hello Cordova\n' + - ' \n' + - ' A sample Apache Cordova application that responds to the deviceready event.\n' + - ' \n' + - ' \n' + - ' Apache Cordova Team\n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' + - '\n'; +var path = require('path'); +var rewire = require('rewire'); +var util = require('../src/cordova/util'); +var cordova_config = require('../src/cordova/config'); +var prepare = rewire('../src/cordova/prepare'); +var restore = require('../src/cordova/restore-util'); +var platforms = require('../src/platforms/platforms'); +var HooksRunner = require('../src/hooks/HooksRunner'); +var Q = require('q'); +var PlatformJson = require('cordova-common').PlatformJson; +var PluginInfoProvider = require('cordova-common').PluginInfoProvider; -describe('prepare command', function() { - var is_cordova, - cd_project_root, - list_platforms, - fire, - parsers = {}, - find_plugins, - cp, - mkdir, - load, platformApi, getPlatformApi; +var project_dir = '/some/path'; +describe('cordova/prepare', function () { + let platform_api_prepare_mock; + let platform_api_add_mock; + let platform_api_remove_mock; beforeEach(function () { - getPlatformApi = spyOn(platforms, 'getPlatformApi').and.callFake(function (platform, rootDir) { + platform_api_prepare_mock = jasmine.createSpy('prepare').and.returnValue(Q()); + platform_api_add_mock = jasmine.createSpy('add').and.returnValue(Q()); + platform_api_remove_mock = jasmine.createSpy('remove').and.returnValue(Q()); + spyOn(platforms, 'getPlatformApi').and.callFake(function (platform, rootDir) { return { - prepare: jasmine.createSpy('prepare').and.returnValue(Q()), + prepare: platform_api_prepare_mock, getPlatformInfo: jasmine.createSpy('getPlatformInfo').and.returnValue({ locations: { www: path.join(project_dir, 'platforms', platform, 'www') } }), + removePlugin: platform_api_add_mock, + addPlugin: platform_api_remove_mock }; }); - is_cordova = spyOn(util, 'isCordova').and.returnValue(project_dir); - cd_project_root = spyOn(util, 'cdProjectRoot').and.returnValue(project_dir); - list_platforms = spyOn(util, 'listPlatforms').and.returnValue(supported_platforms); - fire = spyOn(HooksRunner.prototype, 'fire').and.returnValue(Q()); - - find_plugins = spyOn(util, 'findPlugins').and.returnValue([]); - spyOn(PlatformJson, 'load').and.returnValue(new PlatformJson(null, null, {})); - spyOn(PlatformJson.prototype, 'save'); - load = spyOn(lazy_load, 'based_on_config').and.returnValue(Q()); - cp = spyOn(shell, 'cp').and.returnValue(true); - mkdir = spyOn(shell, 'mkdir'); - spyOn(ConfigParser.prototype, 'write'); - spyOn(xmlHelpers, 'parseElementtreeSync').and.callFake(function() { - return new et.ElementTree(et.XML(TEST_XML)); - }); + spyOn(PlatformJson, 'load'); + spyOn(HooksRunner.prototype, 'fire').and.returnValue(Q()); + spyOn(util, 'isCordova').and.returnValue(true); }); - describe('failure', function() { - it('Test 001 : should not run outside of a cordova-based project by calling util.isCordova', function(done) { - is_cordova.and.returnValue(false); - cd_project_root.and.callThrough(); // undo spy here because prepare depends on cdprojectRoot for isCordova check - prepare().then(function() { - expect('this call').toBe('fail'); - }, function(err) { - expect('' + err).toContain('Current working directory is not a Cordova-based project.'); - }).fin(done); + describe('main method', function () { + beforeEach(function () { + spyOn(cordova_config, 'read').and.returnValue({}); + spyOn(restore, 'installPlatformsFromConfigXML').and.returnValue(Q()); + spyOn(restore, 'installPluginsFromConfigXML').and.returnValue(Q()); + + spyOn(prepare, 'preparePlatforms').and.returnValue(Q); + }); + describe('failure', function () { + it('should invoke util.preProcessOptions as preflight task checker, which, if fails, should trigger promise rejection and only fire the before_prepare hook', function(done) { + spyOn(util, 'cdProjectRoot').and.returnValue(project_dir); --- End diff -- I think it's a cleaner pattern, plus, it forces you to mock out everything right from the beginning, enforcing a truer unit testing style. One more benefit is that within the scope of a single `it`, you can see just what mocks are being tweaked to trigger the behaviour the test is looking to reproduce. So I think it makes clearer the situation under which the test executes. > Speed up cordova-lib tests > -------------------------- > > Key: CB-12361 > URL: https://issues.apache.org/jira/browse/CB-12361 > Project: Apache Cordova > Issue Type: Improvement > Components: cordova-lib > Reporter: Steve Gill > Assignee: Steve Gill > Labels: cordova-next > > * Split out e2e tests into own folder > * stub i/o and network requests > * use local fixtures when possible & makes sense -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org