Skip to content

Commit

Permalink
ci: use github actions
Browse files Browse the repository at this point in the history
* dropped travis ci
* dropped appveyor
* added package-lock.json
* updated coverage to include e2e tests
* updated test scripts
  • Loading branch information
erisu committed May 21, 2020
1 parent 1714953 commit afb025d
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 138 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Node CI

on: [push, pull_request]

jobs:
darwin:
name: NodeJS ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [10.x, 12.x]
os: [macos-latest]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Environment Information
run: |
node --version
npm --version
- name: npm install and test
run: |
npm i -g ios-deploy
npm cit
env:
CI: true

- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true

non-darwin:
name: NodeJS ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [10.x, 12.x]
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Environment Information
run: |
node --version
npm --version
- name: npm install and test
run: |
npm ci
npm run lint
npm run unit-tests
env:
CI: true

- uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
1 change: 0 additions & 1 deletion .ratignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ NSData+Base64.m
Contents.json
jasmine.json
fixtures
appveyor.yml
i386
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions appveyor.yml

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"cordova:platform"
],
"scripts": {
"test": "npm run unit-tests && npm run test:component && npm run objc-tests && npm run e2e-tests",
"pretest": "npm run lint",
"test": "npm run coverage && npm run objc-tests",
"test:component": "jasmine --config=tests/spec/component.json",
"posttest": "npm run lint",
"cover": "nyc jasmine --config=tests/spec/coverage.json",
"coverage": "nyc jasmine --config=tests/spec/coverage.json",
"e2e-tests": "jasmine tests/spec/create.spec.js",
"objc-tests": "npm run objc-tests-lib && npm run objc-tests-framework",
"objc-tests-lib": "npm run xcodebuild -- -scheme CordovaLibTests",
Expand Down
10 changes: 5 additions & 5 deletions tests/spec/component/versions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ if (process.platform === 'darwin') {
() => fail('expected promise rejection'),
error => expect(error).toContain('is not valid tool name')
);
});
}, 10000);

it('should find xcodebuild version.', () => {
return versions.get_tool_version('xcodebuild').then((version) => {
expect(version).not.toBe(undefined);
});
});
}, 10000);

it('should find ios-sim version.', () => {
return versions.get_tool_version('ios-sim').then((version) => {
expect(version).not.toBe(undefined);
});
});
}, 10000);

it('should find ios-deploy version.', () => {
return versions.get_tool_version('ios-deploy').then((version) => {
expect(version).not.toBe(undefined);
});
});
}, 10000);

it('should find pod version.', () => {
return versions.get_tool_version('pod').then((version) => {
expect(version).not.toBe(undefined);
});
});
}, 10000);
});
});
}
3 changes: 2 additions & 1 deletion tests/spec/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"spec_dir": "tests/spec",
"spec_files": [
"unit/**/*[sS]pec.js",
"component/**/*[sS]pec.js"
"component/**/*[sS]pec.js",
"create.spec.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
Expand Down
173 changes: 91 additions & 82 deletions tests/spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,96 +1306,105 @@ describe('prepare', () => {
});
});

describe('<resource-file> tests', () => {
// image-8888.png target attribute is missing in config.xml as a test
const images = [
{
src: 'image-5678.png',
target: 'image-5678.png'
},
{
src: 'image-1234.png',
target: path.join('images', 'image-3456.png')
},
{
src: 'image-8888.png',
target: 'image-8888.png'
/**
* Alternative option is to not use the temp dir for creating test projects folder.
* GitHub Actions temp directory is located on the C drive while the repo contents
* are checkout and run from the D drive. This causes an issue in updateFileResources
* method. macOS and Linux does not have this issue as there isnt a drive letter.
* Testing this method on Windows or Linux might not be required.
*/
if (process.platform !== 'win32') {
describe('<resource-file> tests', () => {
// image-8888.png target attribute is missing in config.xml as a test
const images = [
{
src: 'image-5678.png',
target: 'image-5678.png'
},
{
src: 'image-1234.png',
target: path.join('images', 'image-3456.png')
},
{
src: 'image-8888.png',
target: 'image-8888.png'
}
];
const projectRoot = path.join(FIXTURES, 'resource-file-support');
const updateFileResources = prepare.__get__('updateFileResources');
const cleanFileResources = prepare.__get__('cleanFileResources');
const cfgResourceFiles = new ConfigParser(path.join(FIXTURES, 'resource-file-support', 'config.xml'));

function findImageFileRef (pbxproj, imageFileName) {
const buildfiles = pbxproj.pbxBuildFileSection();
return Object.keys(buildfiles).filter(uuid => {
const filename = buildfiles[uuid].fileRef_comment;
return (filename === imageFileName);
});
}
];
const projectRoot = path.join(FIXTURES, 'resource-file-support');
const updateFileResources = prepare.__get__('updateFileResources');
const cleanFileResources = prepare.__get__('cleanFileResources');
const cfgResourceFiles = new ConfigParser(path.join(FIXTURES, 'resource-file-support', 'config.xml'));

function findImageFileRef (pbxproj, imageFileName) {
const buildfiles = pbxproj.pbxBuildFileSection();
return Object.keys(buildfiles).filter(uuid => {
const filename = buildfiles[uuid].fileRef_comment;
return (filename === imageFileName);
});
}

function findResourcesBuildPhaseRef (pbxproj, ref) {
const resBuildPhase = pbxproj.buildPhaseObject('PBXResourcesBuildPhase', 'Resources');
let resBuildPhaseFileRefs = [];
if (resBuildPhase) {
resBuildPhaseFileRefs = resBuildPhase.files.filter(item => item.value === ref);
function findResourcesBuildPhaseRef (pbxproj, ref) {
const resBuildPhase = pbxproj.buildPhaseObject('PBXResourcesBuildPhase', 'Resources');
let resBuildPhaseFileRefs = [];
if (resBuildPhase) {
resBuildPhaseFileRefs = resBuildPhase.files.filter(item => item.value === ref);
}

return resBuildPhaseFileRefs;
}

return resBuildPhaseFileRefs;
}
it('<resource-file> prepare - copy', () => {
const cordovaProject = {
root: projectRoot,
projectConfig: cfgResourceFiles,
locations: {
plugins: path.join(projectRoot, 'plugins'),
www: path.join(projectRoot, 'www')
}
};

it('<resource-file> prepare - copy', () => {
const cordovaProject = {
root: projectRoot,
projectConfig: cfgResourceFiles,
locations: {
plugins: path.join(projectRoot, 'plugins'),
www: path.join(projectRoot, 'www')
updateFileResources(cordovaProject, p.locations);
// try multiple times (3 in total)
updateFileResources(cordovaProject, p.locations);
updateFileResources(cordovaProject, p.locations);

const project = projectFile.parse(p.locations);

// for the 3 total file references attempted to be added above,
// it should only have one file reference after the fact
for (const image of images) {
// check whether the file is copied to the target location
const copiedImageFile = path.join(project.resources_dir, image.target);
expect(fs.existsSync(copiedImageFile)).toEqual(true);

// find PBXBuildFile file reference
const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target));
expect(imagefileRefs.length).toEqual(1);
// find file reference in PBXResourcesBuildPhase
const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]);
expect(resBuildPhaseFileRefs.length).toEqual(1);
}
};

updateFileResources(cordovaProject, p.locations);
// try multiple times (3 in total)
updateFileResources(cordovaProject, p.locations);
updateFileResources(cordovaProject, p.locations);

const project = projectFile.parse(p.locations);

// for the 3 total file references attempted to be added above,
// it should only have one file reference after the fact
for (const image of images) {
// check whether the file is copied to the target location
const copiedImageFile = path.join(project.resources_dir, image.target);
expect(fs.existsSync(copiedImageFile)).toEqual(true);

// find PBXBuildFile file reference
const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target));
expect(imagefileRefs.length).toEqual(1);
// find file reference in PBXResourcesBuildPhase
const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]);
expect(resBuildPhaseFileRefs.length).toEqual(1);
}
});
});

it('<resource-file> clean - remove', () => {
cleanFileResources(projectRoot, cfgResourceFiles, p.locations);
const project = projectFile.parse(p.locations);

for (const image of images) {
// check whether the file is removed from the target location
const copiedImageFile = path.join(project.resources_dir, image.target);
expect(fs.existsSync(copiedImageFile)).toEqual(false);

// find PBXBuildFile file reference
const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target));
expect(imagefileRefs.length).toEqual(0);
// find file reference in PBXResourcesBuildPhase
const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]);
expect(resBuildPhaseFileRefs.length).toEqual(0);
}
it('<resource-file> clean - remove', () => {
cleanFileResources(projectRoot, cfgResourceFiles, p.locations);
const project = projectFile.parse(p.locations);

for (const image of images) {
// check whether the file is removed from the target location
const copiedImageFile = path.join(project.resources_dir, image.target);
expect(fs.existsSync(copiedImageFile)).toEqual(false);

// find PBXBuildFile file reference
const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target));
expect(imagefileRefs.length).toEqual(0);
// find file reference in PBXResourcesBuildPhase
const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]);
expect(resBuildPhaseFileRefs.length).toEqual(0);
}
});
});
});
}

describe('updateWww method', () => {
const updateWww = prepare.__get__('updateWww');
Expand Down

0 comments on commit afb025d

Please sign in to comment.