Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump deps and add tests #29

Merged
merged 3 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- master
tags:
- '*'

pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

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

steps:
- name: Checking out for ${{ github.ref }}
uses: actions/checkout@v2

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

- run: npx version-from-git --no-git-tag-version
if: ${{ startsWith(github.ref, 'refs/heads/') }}

- run: npm ci

- run: npm run build --if-present

- run: npm test

- run: npm pack

- uses: actions/upload-artifact@v2
if: ${{ matrix.node-version == '14.x' }}
with:
name: npm-tarball
path: '*.tgz'

publish:
needs: build
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}

steps:
- uses: actions/download-artifact@v2
with:
name: npm-tarball

- name: Read package.json
id: read-package-json
run: |
echo "::set-output name=name::$(tar xOf *.tgz package/package.json | jq -r '.name')"
echo "::set-output name=version::$(tar xOf *.tgz package/package.json | jq -r '.version')"
echo "::set-output name=tarball::$(ls *.tgz)"
echo "::set-output name=date::$(date +%Y-%m-%d)"

- name: Run npm publish ${{ steps.read-package-json.outputs.name }}@${{ steps.read-package-json.outputs.version }}
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm publish *.tgz --tag master

- uses: actions/create-release@v1
id: create-release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: '[${{ steps.read-package-json.outputs.version }}] ${{ steps.read-package-json.outputs.date }}'
draft: true

- uses: actions/upload-release-asset@v1
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ./${{ steps.read-package-json.outputs.tarball }}
asset_name: ${{ steps.read-package-json.outputs.tarball }}
10 changes: 10 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
arrowParens: avoid
bracketSpacing: true
jsxBracketSameLine: false
printWidth: 120
proseWrap: preserve
quoteProps: as-needed
semi: true
singleQuote: true
tabWidth: 2
trailingComma: none
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Bump dependencies, in PR [#29](https://github.com/compulim/simple-update-in/pulls/29)
- [`@babel/cli@7.8.4`](https://npmjs.com/package/@babel/cli)
- [`@babel/core@7.9.6`](https://npmjs.com/package/@babel/core)
- [`@babel/plugin-proposal-object-rest-spread@7.9.6`](https://npmjs.com/package/@babel/plugin-proposal-object-rest-spread)
- [`@babel/preset-env@7.9.6`](https://npmjs.com/package/@babel/preset-env)
- [`babel-jest@26.0.1`](https://npmjs.com/package/babel-jest)
- [`coveralls@3.1.0`](https://npmjs.com/package/coveralls)
- [`jest@26.0.1`](https://npmjs.com/package/jest)
- [`regenerator-runtime@0.13.5`](https://npmjs.com/package/regenerator-runtime)
- [`rollup@2.10.9`](https://npmjs.com/package/rollup)
- [`rollup-plugin-babel@4.4.0`](https://npmjs.com/package/rollup-plugin-babel)
- [`rollup-plugin-uglify@6.0.4`](https://npmjs.com/package/rollup-plugin-uglify)

## [2.1.1] - 2019-08-01

### Changed

- Fix [#24](https://github.com/compulim/simple-update-in/issues/24), polyfill `Object.is` for IE11, in PR [#25](https://github.com/compulim/simple-update-in/pull/25)
- Polyfill code is adopted from [`core-js`](https://npmjs.com/package/core-js) to maintain zero dependency

## [2.1.0] - 2019-07-18

### Changed

- Bump dependencies, in PR [#18](https://github.com/compulim/simple-update-in/pulls/18)
- [`@babel/cli@^7.5.5`](https://www.npmjs.com/package/@babel/cli)
- [`@babel/core@^7.5.5`](https://www.npmjs.com/package/@babel/core)
Expand All @@ -30,71 +50,95 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `Object.is` correctly compare between `0` and `-0` (different), and `NaN` and `Number.NaN` (indifferent)

### Added

- Will skip paths containing `__proto__`, `constructor`, and `prototype`, in PR [#19](https://github.com/compulim/simple-update-in/pull/19)

## [2.0.2] - 2018-12-06

### Fixed

- Fix [#16](https://github.com/compulim/simple-update-in/issues/16), parents should not be removed when `updater` is or returned `undefined`, in PR [#17](https://github.com/compulim/simple-update-in/pull/17)

## [2.0.1] - 2018-12-03

### Added

- Emitting UMD bundle for browser
- `<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>`
- `<script>window.simpleUpdateIn({ abc: 123, def: 456 }, ['xyz'], () => 789);</script>`

## [2.0.0] - 2018-12-03

### Added

- Support async predicate
- `await updateIn([1, 2, 3, 4, 5], [v => Promise.resolve(v % 2)], v => v * 10)` will return `[10, 2, 30, 4, 50]`
- Support async update
- `await updateIn([1, 2, 3], [0], v => Promise.resolve(v * 10))` will return `[10, 2, 3]`

### Changed

- Use Node.js 10 and 11 for Travis CI

### Removed

- Removed array insertion using index number of `-1`
- This introduces API inconfirmity: `-1` could means append, prepend, or the last item

## [1.4.0] - 2018-10-08

### Changed

- Add default exports for CommonJS
- Bump
- `@babel/core@7.1.2`
- `merge@1.2.1` (via `npm audit fix`)
- `jest@23.6.0`

## [1.3.1] - 2018-10-05

### Fixed

- Using a predicate on a non-existing key/index should not throw error and return the original value as-is
- `updateIn({}, ['Hello', () => true], () => 'World!'])` will return `{}`
- `updateIn([], [0, () => true], () => 'Aloha'])` will return `[]`

## [1.3.0] - 2018-08-17

### Added

- Support predicate function
- `updateIn([1, 2, 3, 4, 5], [v => v % 2], v => v * 10)` will return `[10, 2, 30, 4, 50]`
- Predicate function can be used as branching function to update multiple subtrees in a single call

## [1.2.0] - 2018-04-14

### Added

- If after `updater` result in nothing change (triple-equal `===`), will return untouched
- `updater` returned `undefined` will be treated as removing the item

### Fixed

- Append not creating sub-structure correctly
- `updateIn([1, 2], [-1, 0], 'Hello')` should return `[1, 2, ['Hello']]` instead of `[1, 2, 'Hello']`

## [1.1.1] - 2018-04-06

### Fixed

- Move `babel` and `gulp` into `devDependencies`

## [1.1.0] - 2018-03-31

### Added

- Automatic expansion
- Replace incompatible types
- Array insertion using index number of `-1`

## [1.0.0] - 2018-03-21

### Added

- Initial commit
8 changes: 8 additions & 0 deletions __tests__/dist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="../dist/simple-update-in.production.min.js"></script>
</head>
<body>
</body>
</html>
24 changes: 24 additions & 0 deletions __tests__/dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @jest-environment jsdom
*/

import 'regenerator-runtime';
import { join } from 'path';
import { JSDOM } from 'jsdom';

async function waitOnce(eventTarget, name) {
return new Promise(resolve => eventTarget.addEventListener(name, resolve, { once: true }));
}

test('Able to load via window.simpleUpdateIn', async () => {
const { window } = await JSDOM.fromFile(join(__dirname, 'dist.html'), {
resources: 'usable',
runScripts: 'dangerously'
});

await waitOnce(window, 'load');

const actual = window.simpleUpdateIn({ one: 1, two: 2 }, ['three'], () => 3);

expect(actual).toEqual({ one: 1, two: 2, three: 3 });
});
3 changes: 3 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testEnvironment": "node"
}
Loading