1# compiler unit testing 2 3**The compiler unit testing for ace2.0.** 4 5## Usage 6Here are simplified instructions of how to get started. The following commands work both on **Windows** and **Linux** platforms. 7 8### 1. Install 9First, enter the root directory of the compiler: 10``` 11$ cd compiler/ 12``` 13And then install the npm dependencies(You must have node&npm installed): 14``` 15$ npm install 16``` 17**Note**: If some errors occur, delete the generated package `node_modules`, config npm proxy and run `npm install` again. 18``` 19npm config set proxy http://username:password@server:port 20npm confit set https-proxy http://username:password@server:port 21``` 22 23### 2. Quick Start 24First, create a new test file or directory in `compiler/test`. 25Write source code in variable 'source', and write expected code in variable 'expectResult': 26``` 27// source code 28export const source: string = `...` 29// expected code 30export const expectResult: string = `...` 31``` 32In the root directory of `compiler/`: 33``` 34$ npm run test 35``` 36All files in the `compiler/test` will be tested. 37 38### 3. Example 391. Create a new test directory `foo` in `compiler`. 402. Create a new test file `bar.ts` in `compiler/foo`. 413. In the file `bar.ts`, write the following lines: 42``` 43export const source: string = ` 44struct MyComponent { 45 build() { 46 } 47}` 48 49export const expectResult: string = 50`class MyComponent { 51 build() { 52 } 53} 54` 55``` 564. In the root directory of `compiler/`: 57``` 58$ npm run test 59``` 605. All files in the `compiler/test` will be tested. The output is like the following lines: 61``` 62 ✓ bar 63 1 passing (1ms) 64``` 65**Note**: If the actual building result is different from the expected result and the output is like the following lines, you should check the error: 66``` 67 1) bar 68 69 0 passing (1ms) 70 1 failing 71 72 1) compiler 73 bar: 74 75 AssertionError: expected 'class MyComponent {\n build() {\n }\n}\n' to deeply equal 'class MyComponent {\n build() {\n \n}\n' 76 + expected - actual 77 78 class MyComponent { 79 build() { 80 - } 81 + 82 } 83``` 84