Sunday, November 20, 2016

Lookup expressjs #2 lib/application.js

* application.js



var compileETag = require('./utils').compileETag;

var slice = Array.prototype.slice;


이처럼 function들을 즉각적으로 사용하지 않고,  variable로 사용하는 컨벤션이 있는데,
딱히 좋은지는 모르겠습니다.

compleEtag function 은 그렇다 치더라도,
slice 의 경우 코드에서 Array.prototype.slice 인지, user defined 된 slice 라는걸 알기 어렵다는 단점이 우선 눈에 띕니다..

좋은 점은 반복적으로 사용되면, 코드를 줄이는 효과가 있을것 같기는 한데,
slice 와 같이 well-known function 에 대해서 user define 하지 않는다는 규칙이 Team 에 존재한다면 괜찮을수 있다 생각됩니다.

그렇지만, new member가 숙지해야 될 규칙이 하나더 생기기에 역시 그렇게 좋은 효과로 보기 어렵습니다.


application.js 는 expressjs application 설정등 초기화하고, application life cycle 로 판단되는데, 일단 살펴 봐야 겠습니다.


app.defaultConfiguration = function defaultConfiguration() {

  var env = process.env.NODE_ENV || 'development';



.....



  debug('booting in %s mode', env);



  this.on('mount', function onmount(parent) {

    // inherit trust proxy

    if (this.settings[trustProxyDefaultSymbol] === true

      && typeof parent.settings['trust proxy fn'] === 'function') {

      delete this.settings['trust proxy'];

      delete this.settings['trust proxy fn'];

    }



    // inherit protos

    this.request.__proto__ = parent.request;

    this.response.__proto__ = parent.response;

    this.engines.__proto__ = parent.engines;

    this.settings.__proto__ = parent.settings;

  });



 ....



  if (env === 'production') {

    this.enable('view cache');

  }



  ...

};


init() -> defaultConfiguration() 을 호출 하는데, 보시는 바와 같이 NODE_ENV 등의 각종 설정들이 초기화 됩니다.
한가지, production 모드 일때 view cache 가 활성화되는걸 볼수 있네요.
이점은 좀 유의 해야 할 필요가 있는것 같습니다.


Look up expressjs #1 ./lib/express.js

개발자로써의 삶을 나태하게 보내는것에 대한 반성으로, 원래 좋아하던 오픈소스 뜯어 보기를 다시한번 하고자 합니다.

지금 주력으로 개발하고 있는 것은 nodejs + expressjs 입니다.
nodejs 는  원래 먼저 보고자 했는데, cpp 로 작성된 프로젝트 이기도 하고, nodejs 코딩 컨벤션에 대해서 좀더 알고 싶은 욕구를 해소하기 위해 expressjs 로 선정했습니다.

* expressjs ( http://express.js.com )

사이트 소개에 따르면 expressjs 는 경량하고도 유여한 Web Application Framework 입니다.
대부분의 nodejs로 구춘된 web application 은 expressjs 를 사용하고 있으며, 저도 현재 프로젝트에 사용하고 있습니다.

원래 이런 framework 선정 전에 먼저 살펴보고, 대안을 찾아 보고 장단점을 비교해봐야 하는데 귀찮아서 바빠서 이과정을 생략하고 도입했습니다. 참 바보 같은 삶을 살고 있습니다.

지금이라도 늦기전에 살펴보도록 하겠습니다.

* index.js , lib/express.js

두파일이 expressjs lookup journey 의 입구 입니다.
예측해보건데, index.js 는 껍데기 이고, lib/express.js 는 좀더 디테일 한 껍데기 일것입니다.

네 index.js 는 lib/express.js를 require하여 export 하는 역할만 하니, skip
lib/express.js 를 살펴보겠습니다.

이 파일도 역시 application.js router.js response.js request.js 를 require 하는 껍데기에 가까운데, application object 생성하는 createApplication() function 이 정의 되어있고, 일부 deprecated method 에 대한 warning 을 담당하고 있습니다.


function createApplication() {

  var app = function(req, res, next) {

    app.handle(req, res, next);

  };



  mixin(app, EventEmitter.prototype, false);

  mixin(app, proto, false);



  app.request = { __proto__: req, app: app };

  app.response = { __proto__: res, app: app };

  app.init();

  return app;

}


음.. 모르는게 한두가지 보이네요
mixin 과 __proto__

* mixin

https://en.wikipedia.org/wiki/Mixin

mixin 은 다른 class 의 method 를 상속하지(inherit) 하지 않고, 가져오는 (include) 개념이다.
언어에 따라 include 라고 하기도 한다고 하니, 그정도로 이해할수 있겠다.

nodejs application object가 EventEmitter와 proto를 mix 인해서 사용하는것으로 보면 될테고,
app 내에서, request, response module을 접근하고자 app.request, app.requese할 assign 하는 개념으로 보면 될것이다.

음.. 여기서 proto 는 또 뭐지 ㅎ


var proto = require('./application');


proto 는 application module 임으로, application은  EventEmitter, Application 모듈이 mixin 되었다고 보면 되겠다.


* __proto__

http://i5on9i.blogspot.kr/2014/09/proto-prototype.html

Tuesday, September 27, 2016

User Interface Testing - Testing with Xcode


Concepts and APIs

UI Testing 은 unit testing과 근본적으로 다르다.
Unit Testing은 app 스코프안에서 앱의 변수, 상태 등등을 전체적으로 접근 하며, function이나 method를 테스트 한다.
반면에 UI Testing은 User Level에서 테스트함으로 앱안의 함수등을 접근 할수 없다.
즉 User 관점에서 테스트 하는것이다.

APIs

- XCUIApplication
- XCUIElement
- XCUIElementQuery

** 가이드 문서에 별다른 내용이 없다 ㅠ
이건 가이드라기 보다 introduction에 가까운거 아닌가, 맨땅에 헤딩좀 해야 겠다.

Writing Tests of Asynchronous Operations- Testing with Xcode


XCTest에서 expectation 을 통해 Async Op.을 테스트 할수 있다.
XCTestCase+AsynchronousTesting.h 참조.


// Test that the document is opened. Because opening is asynchronous,

// use XCTestCase's asynchronous APIs to wait until the document has

// finished opening.

- (void)testDocumentOpening

{

    // Create an expectation object.

    // This test only has one, but it's possible to wait on multiple expectations.

    XCTestExpectation *documentOpenExpectation = [self expectationWithDescription:@"document open"];



    NSURL *URL = [[NSBundle bundleForClass:[self class]]

                              URLForResource:@"TestDocument" withExtension:@"mydoc"];

    UIDocument *doc = [[UIDocument alloc] initWithFileURL:URL];

    [doc openWithCompletionHandler:^(BOOL success) {

        XCTAssert(success);

        // Possibly assert other things here about the document after it has opened...



        // Fulfill the expectation-this will cause -waitForExpectation

        // to invoke its completion handler and then return.

        [documentOpenExpectation fulfill];

    }];



    // The test will pause here, running the run loop, until the timeout is hit

    // or all expectations are fulfilled.

    [self waitForExpectationsWithTimeout:1 handler:^(NSError *error) {

        [doc closeWithCompletionHandler:nil];

    }];

}


Test Basics - Testing with Xcode


* 모든 소프트웨어는 각 컴포턴트(혹은 모듈을) 조합함으로써 만들어지고,
좋은 테스트라함은 해당 소프트웨어의 기능을 모두 아우를수 있는 레벨의 ( 콤포넌트 단위/ 혹은 콤포넌트를 조합하는 High Level)의 테스트를 수행하는것이다.
이를 위해 XCTests가 있다.


* Unit Tests

하위레벨의 콤포넌트(Model, ViewController, etc)를 테스트 하기에 적합.

> xcode 는 앱 뿐만 아니라, Library도 테스트 할수 있게, App/Library 두가지의 Context를 제공한다.

* Performance Mesure

특정 연산에 대한 성능 분석

* UI Tests.

어플리케이션의 workflow를 테스트 할수 있는 도구.



공부하는 사람.

공부하는 사람.

내가 소프트웨어 엔지니어링을 매력적으로 느끼고, 직업으로 삼게 된 가장 큰 계기는,
이 직업은 꾸준히 공부할 수 있는, 아니 해야만 하는 직업이기 때문이다.

요 몇 년 나는 제대로 된 공부를 하지 않았다.
새로운 기술을 익히고 프로젝트에 적용 하는 것은 그 이전에도 해왔던 것으로 나에게 공부 코스트가 그렇게 큰일은 아니다.

삶의 권태를 느끼고 나를 둘러싼 환경을 변화시키고자 아등바등하고 있는 요즘,
또 한 번 내 이런 모습을 실감하고 나 자신부터 다시 붙잡고자 노력하고 있다.

공부하는 사람.
참 아름다운 말 아닌가. 꾸준히 나아가보자.

Monday, September 26, 2016

Testing with Xcode.


  • Quick Start. Beginning with Xcode 5 and the introduction of the XCTest framework, the process of configuring projects for testing has been streamlined and automated with the test navigator to ease bringing tests up and running.
  • Performance Measurement. Xcode 6 and later includes the ability to create tests that allow you to measure and track performance changes against a baseline.
  • UI Testing. Xcode 7 adds capabilities for writing tests that exercise an app’s UI. It includes the ability to record UI interactions into source code that you can transform into tests.
  • Continuous Integration and Xcode Server. Xcode tests can be executed using command-line scripts or configured to be executed by bots on a Mac running Xcode Server automatically.
  • Modernization. Xcode includes a migrator for converting projects that have OCUnit tests to have XCTest tests. 


See Also