Skip to content

Commit

Permalink
Chore: adds appveyor
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed May 12, 2021
1 parent 5693813 commit d560b4e
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 13 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ Boilerplate for creating npm packages.
- [Contribute](#contribute)

## Requirements
[![Platform Status][appveyor-badge]][appveyor-url]

To use library you need to have [node](https://nodejs.org) and [npm](https://www.npmjs.com) installed in your machine:

* node `6.0+`
* npm `3.0+`
* node `>=10`
* npm `>=6`

## Installation

Expand Down Expand Up @@ -104,3 +106,8 @@ The message summary should be a one-sentence description of the change. The issu
[npm-downloads-badge]: https://img.shields.io/npm/dw/npm-boilerplate
[npm-size-badge]: https://img.shields.io/bundlephobia/min/npm-boilerplate
[npm-size-url]: https://bundlephobia.com/result?p=npm-boilerplate

[appveyor-badge]: https://ci.appveyor.com/api/projects/status/lik73h3vxd7687pr/branch/master?svg=true
[appveyor-url]: https://ci.appveyor.com/project/pustovitDmytro/npm-boilerplate/branch/master


145 changes: 145 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
version: "{build}"
environment:
TimeOutMins: 2
matrix:
- job_name: Build
appveyor_build_worker_image: Ubuntu
nodejs_version: 14

# Ubuntu

- job_name: Ubuntu Node.js v.10
job_group: Tests
appveyor_build_worker_image: Ubuntu
job_depends_on: Build
nodejs_version: 10

- job_name: Ubuntu Node.js v.12
job_group: Tests
appveyor_build_worker_image: Ubuntu
job_depends_on: Build
nodejs_version: 12

- job_name: Ubuntu Node.js v.14
job_group: Tests
appveyor_build_worker_image: Ubuntu
job_depends_on: Build
nodejs_version: 14

- job_name: Ubuntu Node.js v.16
job_group: Tests
appveyor_build_worker_image: Ubuntu
job_depends_on: Build
nodejs_version: 16

# MacOS

- job_name: macOS Node.js v.10
job_group: Tests
appveyor_build_worker_image: macos
job_depends_on: Build
nodejs_version: 10

- job_name: macOS Node.js v.12
job_group: Tests
appveyor_build_worker_image: macos
job_depends_on: Build
nodejs_version: 12

- job_name: macOS Node.js v.14
job_group: Tests
appveyor_build_worker_image: macos
job_depends_on: Build
nodejs_version: 14

- job_name: macOS Node.js v.16
job_group: Tests
appveyor_build_worker_image: macos
job_depends_on: Build
nodejs_version: 16

# Windows

- job_name: Windows Node.js v.10
job_group: Tests
appveyor_build_worker_image: Visual Studio 2019
job_depends_on: Build
nodejs_version: 10

- job_name: Windows Node.js v.12
job_group: Tests
appveyor_build_worker_image: Visual Studio 2019
job_depends_on: Build
nodejs_version: 12

- job_name: Windows Node.js v.14
job_group: Tests
appveyor_build_worker_image: Visual Studio 2019
job_depends_on: Build
nodejs_version: 14

- job_name: Windows Node.js v.16
job_group: Tests
appveyor_build_worker_image: Visual Studio 2019
job_depends_on: Build
nodejs_version: 16

matrix:
allow_failures:
- nodejs_version: 16

artifacts:
- path: tmp
name: package-tests

for:

-
matrix:
only:
- job_name: Build

build_script:
- sh: nvm install $nodejs_version
- sh: nvm use $nodejs_version
- sh: npm config get user-agent
- npm install
- ./bin/pack-tests.sh
-
matrix:
only:
- job_group: Tests
install:
- sh: nvm install $nodejs_version
- sh: nvm use $nodejs_version
- ps: if ($isWindows) { Install-Product node $env:nodejs_version $env:platform }
- npm config get user-agent
before_build:
- ps: |
$headers = @{
"Authorization" = "Bearer $ApiKey"
"Content-type" = "application/json"
}
[datetime]$stop = ([datetime]::Now).AddMinutes($env:TimeOutMins)
[bool]$success = $false
while(!$success -and ([datetime]::Now) -lt $stop) {
$project = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" -Headers $headers -Method GET

$jobToWaitJson = $project.build.jobs | where {$_.name -eq "Build"}
$success = $jobToWaitJson.status -eq "success"
$jobToWaitId = $jobToWaitJson.jobId;
if (!$success) {Start-sleep 5}
}

if (!$success) {throw "Job `"Build`" was not finished in $env:TimeOutMins minutes"}
if (!$jobToWaitId) {throw "Unable t get JobId for the job `"Build`""}

Start-FileDownload https://ci.appveyor.com/api/buildjobs/$jobToWaitId/artifacts/package-tests.zip
build_script:
- 7z x package-tests.zip
- cd package-tests
- npm i
test_script:
- sh: npm run test
- cmd: npm run test-win
10 changes: 7 additions & 3 deletions bin/pack-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ const TEST_MODULES = [
const resolveIgnoreRegexp = `^(?!${TEST_MODULES.join('|')}).*$`;

async function run(tarFilePath) {
const nodeModulesPath = [ 'node_modules', packajeInfo.name, 'lib' ];

COPY.push([ tarFilePath, tarFilePath ]);
const testConfig = {
'name' : `${packajeInfo.name}-tests`,
'version' : '1.0.0',
'version' : packajeInfo.version,
'scripts' : {
'test' : `ENTRY="./node_modules/${packajeInfo.name}/lib" mocha --config .mocharc.json tests.js`
'test-win' : `set ENTRY=${path.win32.join(...nodeModulesPath)}&& mocha --config .mocharc.json tests.js`,
'test' : `ENTRY="${path.join(...nodeModulesPath)}" mocha --config .mocharc.json tests.js`
},
'dependencies' : {
[packajeInfo.name] : path.resolve(tarFilePath)
[packajeInfo.name] : tarFilePath
},
'devDependencies' : TEST_MODULES.reduce((prev, cur) => ({
[cur] : packajeInfo.devDependencies[cur],
Expand Down
7 changes: 7 additions & 0 deletions bin/pack-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

echo "Packing ..."
TAR_NAME="$(npm pack 2>&1 | tail -1)"
./bin/pack-tests.js $TAR_NAME
mv $TAR_NAME tmp/package-tests/
11 changes: 6 additions & 5 deletions bin/test-package.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
set -e

echo "Packing ..."
TAR_NAME="$(npm pack 2>&1 | tail -1)"
./bin/pack-tests.js $TAR_NAME
echo "Packing ..."
./bin/pack-tests.sh

echo "Testing ..."
echo "Install ..."
cd ./tmp/package-tests
npm i
npm i --no-audit

echo "Test ..."
npm test
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"bugs": {
"url": "https://github.com/pustovitDmytro/npm-boilerplate/issues"
},
"engines": {
"node": ">=10"
},
"homepage": "https://github.com/pustovitDmytro/npm-boilerplate#readme",
"devDependencies": {
"@babel/cli": "^7.2.3",
Expand Down
18 changes: 15 additions & 3 deletions tests/init.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
// eslint-disable-next-line import/no-commonjs
/* eslint-disable import/no-commonjs */
const { Module } = require('module');
const path = require('path');

function clearRequireCache() {
Object.keys(require.cache).forEach((key) => {
delete require.cache[key];
});
}

function isPathInside(childPath, parentPath) {
const relation = path.relative(parentPath, childPath);

return Boolean(
relation &&
relation !== '..' &&
!relation.startsWith(`..${path.sep}`) &&
relation !== path.resolve(childPath)
);
}

const ROOT_FOLDER = process.cwd();

function preventParentScopeModules() {
const nodeModulePaths = Module._nodeModulePaths;

Module._nodeModulePaths = function (from) {
const originalPath = nodeModulePaths.call(this, from);
const insideRootPaths = originalPath.filter(function (path) {
return path.match(ROOT_FOLDER);
const insideRootPaths = originalPath.filter(function (p) {
return isPathInside(p, ROOT_FOLDER);
});

return insideRootPaths;
Expand Down

0 comments on commit d560b4e

Please sign in to comment.