Skip to content

Commit

Permalink
Standardise build system, fixing TS build
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjwest committed Jun 27, 2020
1 parent 9dd47eb commit 7d86db7
Show file tree
Hide file tree
Showing 14 changed files with 702 additions and 127 deletions.
66 changes: 38 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ references:
v1-dependency-yarn-{{ .Branch }}-
yarn-backup-cache-key-no-branch: &yarn-backup-cache-key-no-branch
v1-dependency-yarn-
node-8: &node-8
circleci/node:8.17.0
node-10: &node-10
circleci/node:10.17.0
circleci/node:10.19.0
node-12: &node-12
circleci/node:12.13.0
circleci/node:12.18.0
node-14: &node-14
circleci/node:14.3.0
node-8-latest: &node-8-latest
circleci/node:8
circleci/node:14.4.0
node-10-latest: &node-10-latest
circleci/node:10
node-12-latest: &node-12-latest
Expand Down Expand Up @@ -81,113 +77,127 @@ commands:
name: Audit production dependencies
command: yarn audit-dependencies

build:
steps:
- run:
name: Build project
command: yarn build

tests:
steps:
- run:
name: Unit tests
name: TS Unit tests
command: yarn test:coverage
- store_artifacts:
path: coverage
- store_test_results:
path: ~/test-results/

tests-es5:
steps:
- run:
name: ES5 Unit tests
command: yarn test:unit:es5

tests-es6:
steps:
- run:
name: ES6 Unit tests
command: yarn test:unit:es6

jobs:
checks:
docker:
- image: *node-10
- image: *node-14
steps:
- checkout
- install-dependencies
- checks

test-node-8:
docker:
- image: *node-8
steps:
- checkout
- install-dependencies
- tests

test-node-10:
docker:
- image: *node-10
steps:
- checkout
- install-dependencies
- build
- tests
- tests-es5

test-node-12:
docker:
- image: *node-12
steps:
- checkout
- install-dependencies
- build
- tests
- tests-es5
- tests-es6

test-node-14:
docker:
- image: *node-14
steps:
- checkout
- install-dependencies
- build
- tests
- tests-es5
- tests-es6
- coveralls/upload

checks-latest:
docker:
- image: *node-10
- image: *node-14
steps:
- checkout
- install-dependencies-latest
- checks

test-node-8-latest:
docker:
- image: *node-8-latest
steps:
- checkout
- install-dependencies-latest
- tests

test-node-10-latest:
docker:
- image: *node-10-latest
steps:
- checkout
- install-dependencies-latest
- build
- tests
- tests-es5

test-node-12-latest:
docker:
- image: *node-12-latest
steps:
- checkout
- install-dependencies-latest
- build
- tests
- tests-es5

test-node-14-latest:
docker:
- image: *node-14-latest
steps:
- checkout
- install-dependencies-latest
- build
- tests
- tests-es5
- tests-es6

workflows:
version: 2
test:
jobs:
- checks
- test-node-8
- test-node-10
- test-node-12
- test-node-14

nightly:
jobs:
- checks-latest
- test-node-8-latest
- test-node-10-latest
- test-node-12-latest
- test-node-14-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/build
/build/es5
/build/es6
/.nyc_output
/coverage
2 changes: 2 additions & 0 deletions build/wrapper.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import multiline from './es5/index';
export = multiline;
3 changes: 3 additions & 0 deletions build/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const multiline = require('./es5/index.cjs').default;

module.exports = multiline;
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"name": "multiline-ts",
"version": "1.1.1",
"description": "Readable multiline template strings",
"type": "module",
"main": "./build/es5/multiline.cjs",
"engines": {
"node": ">=8"
},
"main": "./build/wrapper.js",
"exports": {
"import": "./build/multiline.js",
"require": "./build/es5/multiline.cjs"
"import": "./build/es6/index.mjs",
"require": "./build/wrapper.js"
},
"engines": {
"node": ">=10"
},
"repository": {
"type": "git",
Expand All @@ -34,17 +33,19 @@
"scripts": {
"audit-dependencies": "yarn audit; [[ $? -ge 4 ]] && exit 1 || exit 0",
"build": "yarn build:es6 && yarn build:es5",
"build:es6": "tsc --project tsconfig-build.json",
"build:es6": "rm -rf build/es6 && tsc --project tsconfig-build-es6.json && renamer --find .js --replace .mjs build/es6/**",
"build:es5": "rm -rf build/es5 && tsc --project tsconfig-build-es5.json && renamer --find .js --replace .cjs build/es5/**",
"lint:ts": "tslint --format verbose --project tsconfig.json",
"test:coverage": "rm -rf coverage && NODE_DEBUG=nyc nyc mocha 'tests/**/*.ts'",
"test:unit": "mocha --require ts-node/register 'tests/**/*.ts'"
"test:unit": "mocha --require ts-node/register 'tests/**/*.ts'",
"test:unit:es5": "mocha 'tests/*.cjs'",
"test:unit:es6": "mocha 'tests/*.mjs'"
},
"dependencies": {},
"devDependencies": {
"@types/mocha": "5.2.7",
"@types/node": "^14.0.6",
"mocha": "^6.1.4",
"mocha": "^8.0.1",
"mocha-circleci-reporter": "^0.0.3",
"nyc": "14.1.1",
"renamer": "1.1.4",
Expand Down
File renamed without changes.
164 changes: 164 additions & 0 deletions tests/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
const assert = require('assert');

const multiline = require('../build/wrapper');

describe('utils/multiline', () => {
it('Returns a string indented correctly without leading/trailing newline', (() => {
const expectedString = [
'foo',
' bar',
' zim',
].join('\n');

assert.strictEqual(multiline`
foo
bar
zim
`, expectedString);
}));

it('Returns a string without adjusting indentation', (() => {
const expectedString = [
'foo',
' bar',
' zim',
].join('\n');

assert.strictEqual(multiline`
foo
bar
zim
`, expectedString);
}));

it('Returns a string indented correctly with tabs', (() => {
const expectedString = [
'foo',
'\tbar',
'',
'\t\tzim',
].join('\n');

assert.strictEqual(multiline`
\t\t\tfoo
\t\t\t\tbar
\t\t\t\t\tzim
`, expectedString);
}));

it('Returns a string indented correctly with mixed tabs and spaces, you monster', (() => {
const expectedString = [
'foo',
'',
'\tbar',
'\t\tzim',
].join('\n');

assert.strictEqual(multiline`
\tfoo
\t
\t\tbar
\t\t\tzim
`, expectedString);
}));

it('Returns a string with extra trailing newlines', (() => {
const expectedString = [
'foo',
' bar',
' zim',
'',
'',
].join('\n');

assert.strictEqual(multiline`
foo
bar
zim
`, expectedString);
}));

it('Returns a string with extra leading newlines', (() => {
const expectedString = [
'',
'foo',
' bar',
' zim',
'',
'',
].join('\n');

assert.strictEqual(multiline`
foo
bar
zim
`, expectedString);
}));

it('Returns a string with placeholders indented correctly', (() => {
const expectedString = [
'foo',
' zim',
' bar',
' zig',
].join('\n');

const zim = 'zim';
const zig = 'zig';
assert.strictEqual(multiline`
foo
${zim}
bar
${zig}
`, expectedString);
}));

it('Returns a string with multiline placeholders indented correctly', (() => {
const expectedString = [
'foo',
' zim',
' zip',
' zig',
].join('\n');

const list = ['zim', 'zip', 'zig'].join('\n');
assert.strictEqual(multiline`
foo
${list}
`, expectedString);
}));

it('Returns a string with consecutive placeholders indented correctly', (() => {
const expectedString = [
'foo',
' zim: zig',
].join('\n');

const zim = 'zim';
const zig = 'zig';
assert.strictEqual(multiline`
foo
${zim}: ${zig}
`, expectedString);
}));

it('Returns a string indented correctly when called as a function', (() => {
const expectedString = [
'foo',
' bar',
' zim',
].join('\n');

assert.strictEqual(multiline(`
foo
bar
zim
`), expectedString);
}));
});
Loading

0 comments on commit 7d86db7

Please sign in to comment.