Skip to content

refactor(package): update module #206

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

Merged
merged 1 commit into from
Feb 9, 2019
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
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ jobs:
paths:
- "node_modules"

# Build
# - run:
# name: Build
# command: |
# mkdir -p dist
# yarn build

# Test
- run:
name: Tests
command: yarn test && yarn codecov
command: yarn test

# Coverage
- run:
name: Coverage
command: yarn codecov
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Common
node_modules
dist
.nuxt
coverage

# Plugin
lib/plugin.js
29 changes: 4 additions & 25 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
module.exports = {
root: true,
// parser: 'babel-eslint',
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
env: {
browser: true,
node: true,
jest: true
},
extends: 'standard',
plugins: [
'jest',
'vue'
],
rules: {
// Allow paren-less arrow functions
'arrow-parens': 0,
// Allow async-await
'generator-star-spacing': 0,
// Allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// Do not allow console.logs etc...
'no-console': 2
},
globals: {
'jest/globals': true,
jasmine: true
}
extends: [
'@nuxtjs'
]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ node_modules
*.log*
.nuxt
.vscode
.DS_STORE
.DS_Store
coverage
_book
dist
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Nuxt Community
Copyright (c) Nuxt Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
# 📦 Axios Module

> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Circle CI][circle-ci-src]][circle-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![Dependencies][david-dm-src]][david-dm-href]
[![Standard JS][standard-js-src]][standard-js-href]

<p align="center">
<a href="https://david-dm.org/nuxt-community/axios-module">
<img alt="" src="https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square">
</a>
<a href="https://standardjs.com">
<img alt="" src="https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square">
</a>
<a href="https://circleci.com/gh/nuxt-community/axios-module">
<img alt="" src="https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square">
</a>
<a href="https://codecov.io/gh/nuxt-community/axios-module">
<img alt="" src="https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square">
</a>
<br>
<a href="https://npmjs.com/package/@nuxtjs/axios">
<img alt="" src="https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square">
</a>
<a href="https://npmjs.com/package/@nuxtjs/axios">
<img alt="" src="https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square">
</a>
</p>
> Secure and Easy <a href="https://github.com/mzabriskie/axios">Axios</a> integration with Nuxt.js.

## ✅ Features

Expand All @@ -46,4 +31,20 @@

## 📑 License

[MIT License](./LICENSE) - Nuxt Community
[MIT License](./LICENSE)

Copyright (c) Nuxt Community

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/dt/@nuxtjs/axios.svg?style=flat-square
[npm-version-href]: https://npmjs.com/package/@nuxtjs/axios
[npm-downloads-src]: https://img.shields.io/npm/v/@nuxtjs/axios/latest.svg?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/axios
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/axios-module.svg?style=flat-square
[circle-ci-href]: https://circleci.com/gh/nuxt-community/axios-module
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/axios-module.svg?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-community/axios-module
[david-dm-src]: https://david-dm.org/nuxt-community/axios-module/status.svg?style=flat-square
[david-dm-href]: https://david-dm.org/nuxt-community/axios-module
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
[standard-js-href]: https://standardjs.com
11 changes: 11 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
presets: [
[
'@babel/preset-env', {
targets: {
esmodules: true
}
}
]
]
}
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@commitlint/config-conventional'
]
}
7 changes: 7 additions & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
hooks: {
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
'pre-commit': 'yarn lint',
'pre-push': 'yarn lint'
}
}
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.js',
'!lib/plugin.js'
],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/lib/$1',
'^~~$': '<rootDir>',
'^@@$': '<rootDir>',
'^@/(.*)$': '<rootDir>/lib/$1'
},
transform: {
'^.+\\.js$': 'babel-jest'
}
}
5 changes: 3 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const consola = require('consola')

const logger = consola.withScope('nuxt:axios')

module.exports = function nuxtAxios (_moduleOptions) {
function axiosModule(_moduleOptions) {
// Combine options
const moduleOptions = Object.assign({}, this.options.axios, _moduleOptions)

Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = function nuxtAxios (_moduleOptions) {

// Register plugin
this.addPlugin({
src: path.resolve(__dirname, 'plugin.template.js'),
src: path.resolve(__dirname, 'plugin.js'),
fileName: 'axios.js',
options
})
Expand All @@ -99,4 +99,5 @@ module.exports = function nuxtAxios (_moduleOptions) {
logger.debug(`browserBaseURL: ${options.browserBaseURL}`)
}

module.exports = axiosModule
module.exports.meta = require('../package.json')
File renamed without changes.
56 changes: 25 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "5.3.6",
"description": "Secure and easy axios integration with Nuxt.js",
"license": "MIT",
"contributors": [
"Pooya Parsa <[email protected]>"
],
"main": "lib/module.js",
"types": "index.d.ts",
"repository": "https://github.com/nuxt-community/axios-module",
Expand All @@ -12,48 +15,39 @@
"scripts": {
"dev": "nuxt test/fixture",
"lint": "eslint lib test",
"test": "npm run lint && jest",
"release": "standard-version && git push --follow-tags && npm publish",
"prepare": "npm run test"
"test": "yarn lint && jest",
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
},
"eslintIgnore": [
"*.template.*"
],
"files": [
"lib",
"src",
"dist",
"index.d.ts"
],
"jest": {
"testEnvironment": "node",
"coverageDirectory": "./coverage/",
"collectCoverage": true,
"collectCoverageFrom": [
"lib",
"test",
"!test/fixture"
]
},
"dependencies": {
"@nuxtjs/proxy": "^1.3.1",
"axios": "^0.18.0",
"axios-retry": "^3.1.2",
"consola": "^2.4.0"
},
"devDependencies": {
"codecov": "^3.1.0",
"eslint": "^5.13.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.2.2",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.1.0",
"jest": "^24.1.0",
"jsdom": "^13.2.0",
"nuxt-edge": "^2.3.0-25706271.cca799c",
"standard-version": "^4.4.0"
"@babel/core": "latest",
"@babel/preset-env": "latest",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@nuxtjs/eslint-config": "latest",
"babel-eslint": "latest",
"babel-jest": "latest",
"codecov": "latest",
"eslint": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-jest": "latest",
"eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest",
"eslint-plugin-standard": "latest",
"eslint-plugin-vue": "latest",
"husky": "latest",
"jest": "latest",
"nuxt-edge": "latest",
"standard-version": "latest"
}
}
20 changes: 11 additions & 9 deletions test/axios.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.setTimeout(60000)

const { Nuxt, Builder } = require('nuxt-edge')
const axios = require('axios')
const config = require('./fixture/nuxt.config')
Expand All @@ -18,26 +20,26 @@ describe('axios module', () => {

await new Builder(nuxt).build()
await nuxt.listen(3000)
}, 60000)
})

afterAll(async () => {
await nuxt.close()
})

test('baseURL', () => {
expect(addTemplate).toBeDefined()
let call = addTemplate.mock.calls.find(args =>
args[0].src.includes('plugin.template.js')
const call = addTemplate.mock.calls.find(args =>
args[0].src.includes('plugin.js')
)
let options = call[0].options
const options = call[0].options
expect(options.baseURL.toString()).toBe(
`http://localhost:3000/test_api`
)
expect(options.browserBaseURL.toString()).toBe('/test_api')
})

test('asyncData', async () => {
let html = (await axios.get(url('/asyncData'))).data
const html = (await axios.get(url('/asyncData'))).data
expect(html).toContain('foo/bar')
})

Expand Down Expand Up @@ -65,10 +67,10 @@ describe('axios module', () => {
.then(h => /session-[0-9]+/.exec(h))
.then(m => (m && m[0] ? m[0] : null))

let a = await makeReq()
let b = await makeReq(true)
let c = await makeReq()
let d = await makeReq(true)
const a = await makeReq()
const b = await makeReq(true)
const c = await makeReq()
const d = await makeReq(true)

expect(a).toBeNull()
expect(b).not.toBeNull()
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
path: '/test_api',
handler (req, res) {
handler(req, res) {
res.end(JSON.stringify({
url: req.url,
method: req.method
Expand Down
4 changes: 3 additions & 1 deletion test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = {
render: {
resourceHints: false
},
modules: ['@@'],
modules: [
{ handler: require('../../') }
],
serverMiddleware: ['~/api.js'],
axios: {
prefix: `/test_api`,
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/plugins/axios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function ({ $axios, redirect }) {
$axios.onRequest(config => {
$axios.onRequest((config) => {
// eslint-disable-next-line no-console
console.log('SPY: ' + config.url)

Expand Down
2 changes: 1 addition & 1 deletion test/fixture/store/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
actions: {
nuxtServerInit ({ commit }, ctx) {
nuxtServerInit({ commit }, ctx) {
if (!ctx.$axios) {
throw new Error('$axios is not defined!')
}
Expand Down
Loading