Skip to content

Commit

Permalink
Merge pull request #29 from axelpale/feature-actions
Browse files Browse the repository at this point in the history
Feature: setup GitHub Actions
  • Loading branch information
axelpale committed Jan 8, 2024
2 parents 23de008 + 46ec337 commit 1766dfc
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/genversion-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Genversion CI
run-name: ${{ github.actor }} is testing genversion

on: [push]

jobs:
test-genversion:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.github
/doc
/test

Expand Down
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Logo](doc/genversion-logo-halo.png?raw=true "Abracadabra...and behold!")

[![Travis build status](https://img.shields.io/travis/com/axelpale/genversion)](https://app.travis-ci.com/github/axelpale/genversion)
[![GitHub Actions workflow status](https://img.shields.io/github/actions/workflow/status/axelpale/genversion/genversion-ci.yml)](https://github.com/axelpale/genversion/actions/workflows/genversion-ci.yml)
[![npm version](https://img.shields.io/npm/v/genversion?color=green)](https://www.npmjs.com/package/genversion)
[![license](https://img.shields.io/npm/l/genversion)](#license)
[![npm downloads](https://img.shields.io/npm/dm/genversion?color=green)](https://www.npmjs.com/package/genversion)
Expand Down
6 changes: 3 additions & 3 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const stringify = (value, options) => {
// - unescaped double or single quotes '
if (quote === '\'') {
// escape unescaped single quote
const escapedValue = value.replaceAll('\'', '\\\'')
const escapedValue = value.replace(/'/g, '\\\'')
return quote + escapedValue + quote
} else if (quote === '"') {
// escape unescaped double quote
const escapedValue = value.replaceAll('"', '\\"')
const escapedValue = value.replace(/"/g, '\\"')
return quote + escapedValue + quote
} else if (quote === '`') {
// escape unescaped backtick
const escapedValue = value.replaceAll('`', '\\`')
const escapedValue = value.replace(/`/g, '\\`')
return quote + escapedValue + quote
}
// else
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
},
"devDependencies": {
"fs-extra": "^10.0.1",
"mocha": "^10.2.0",
"mocha": "^8.4.0",
"should": "^13.1.0",
"standard": "^17.1.0"
"standard": "^16.0.4"
},
"engines": {
"node": ">=10.0.0"
Expand Down
60 changes: 60 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,66 @@ describe('genversion cli', () => {
})
})

it('should handle single quotes in properties', (done) => {
const clit = new CliTest()
const cmd = GENERATE_COMMAND + ' ' +
'--source ./test/fixture ' +
'--property author ' + P
clit.exec(cmd, (err, response) => {
if (err) {
return done(err)
}

readTemp().should.equal(SIGNATURE +
'module.exports = { ' +
'name: \'Fo\\\'o "Bar" l`Baz\'' +
' }\n'
)

return done()
})
})

it('should handle double quotes in properties', (done) => {
const clit = new CliTest()
const cmd = GENERATE_COMMAND + ' ' +
'--source ./test/fixture ' +
'--property author --double ' + P
clit.exec(cmd, (err, response) => {
if (err) {
return done(err)
}

readTemp().should.equal(SIGNATURE +
'module.exports = { ' +
'name: "Fo\'o \\"Bar\\" l`Baz"' +
' }\n'
)

return done()
})
})

it('should handle backticks in properties', (done) => {
const clit = new CliTest()
const cmd = GENERATE_COMMAND + ' ' +
'--source ./test/fixture ' +
'--property author -b ' + P
clit.exec(cmd, (err, response) => {
if (err) {
return done(err)
}

readTemp().should.equal(SIGNATURE +
'module.exports = { ' +
'name: `Fo\'o "Bar" l\\`Baz`' +
' }\n'
)

return done()
})
})

it('should not understand multiple property flags', (done) => {
const clit = new CliTest()
const cmd = GENERATE_COMMAND + ' --property name ' +
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"keywords": ["foo", "bar"],
"main": "index.js",
"license": "MIT",
"author": {
"name": "Fo'o \"Bar\" l`Baz"
},
"dependencies": {},
"engines": {
"node": ">=10.0.0",
Expand Down

0 comments on commit 1766dfc

Please sign in to comment.