Skip to content

Commit

Permalink
Merge pull request #23 from fringers/nuxt-property-decorator-support
Browse files Browse the repository at this point in the history
#22 Nuxt.js property decorator support
  • Loading branch information
JKrol authored Oct 19, 2020
2 parents 96ff54a + f062333 commit aa73570
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,33 @@ npm install vue-deprecate
```

## Setup

### Default setup

```js
import Vue from 'vue';
import VueDeprecate from 'vue-deprecate';

Vue.use(VueDeprecate);
```


### Nuxt.js setup

Create file `plugins/vue-deprecate.js`:
```js
import Vue from 'vue'
import VueDeprecate from 'vue-deprecate';

Vue.use(VueDeprecate);
```
Then add the file path inside the `plugins` key of `nuxt.config.js`:
```js
export default {
plugins: ['@/plugins/vue-deprecate.js']
}
```

## Usage

Deprecate component:
Expand Down Expand Up @@ -66,6 +86,19 @@ Deprecate property:
};
```

### Usage with property decorators (like vue-property-decorator/nuxt-property-decorator)

```js
import { Vue, Component } from 'nuxt-property-decorator'

@Component({
deprecated: true,
})
export default class Test extends Vue {
}
```


## Features

You can:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-deprecate",
"version": "0.3.0",
"version": "0.3.2",
"author": "fringers",
"scripts": {
"build": "vue-cli-service build --target lib src/deprecate.ts --mode production",
Expand Down
2 changes: 1 addition & 1 deletion src/deprecate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const VueDeprecate: PluginObject<VueDeprecateOptions> = {
install: function (vue: typeof Vue, options: VueDeprecateOptions = defaultOptions) {
vue.mixin({
created: function () {
if (process.env.NODE_ENV === 'production' && options && !options.enabledOnProduction) {
if (!vue.config.devtools && options && !options.enabledOnProduction) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/components.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Components', () => {

const localVue = createLocalVue()
localVue.use(VueDeprecate);
localVue.config.devtools = true;

shallowMount(component, {
localVue,
Expand Down
48 changes: 21 additions & 27 deletions tests/unit/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ describe('Options', () => {
};

// TODO: fix types
function mountWithPluginSpy(component: any, options?: any) {
function mountWithPluginSpy(component: any, options?: any, devtools: boolean = true) {
const installSpy = jest.spyOn(VueDeprecate, 'install');

const localVue = createLocalVue()
localVue.use(VueDeprecate, options);
localVue.config.devtools = devtools;

shallowMount(component, {
localVue,
Expand All @@ -30,18 +31,6 @@ describe('Options', () => {
}

describe('enabledOnProduction', () => {
const OLD_ENV = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...OLD_ENV };
delete process.env.NODE_ENV;
});

afterEach(() => {
process.env = OLD_ENV;
});

it('log warnings if no options and not production', () => {
const warnMock = jest.fn();
console.warn = warnMock;
Expand Down Expand Up @@ -88,8 +77,7 @@ describe('Options', () => {
const warnMock = jest.fn();
console.warn = warnMock;

process.env.NODE_ENV = 'production';
mountWithPluginSpy(deprecatedComponent);
mountWithPluginSpy(deprecatedComponent, undefined, false);

expect(warnMock).not.toHaveBeenCalled();
});
Expand All @@ -98,10 +86,12 @@ describe('Options', () => {
const warnMock = jest.fn();
console.warn = warnMock;

process.env.NODE_ENV = 'production';
mountWithPluginSpy(deprecatedComponent, {
someProp: 'value',
});
mountWithPluginSpy(deprecatedComponent,
{
someProp: 'value',
},
false
);

expect(warnMock).not.toHaveBeenCalled();
});
Expand All @@ -110,10 +100,12 @@ describe('Options', () => {
const warnMock = jest.fn();
console.warn = warnMock;

process.env.NODE_ENV = 'production';
mountWithPluginSpy(deprecatedComponent, {
enabledOnProduction: true,
});
mountWithPluginSpy(deprecatedComponent,
{
enabledOnProduction: true,
},
false
);

expect(warnMock).toHaveBeenCalledTimes(2);
});
Expand All @@ -122,10 +114,12 @@ describe('Options', () => {
const warnMock = jest.fn();
console.warn = warnMock;

process.env.NODE_ENV = 'production';
mountWithPluginSpy(deprecatedComponent, {
enabledOnProduction: false,
});
mountWithPluginSpy(deprecatedComponent,
{
enabledOnProduction: false,
},
false
);

expect(warnMock).not.toHaveBeenCalled();
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Props', () => {

const localVue = createLocalVue()
localVue.use(VueDeprecate);
localVue.config.devtools = true;

shallowMount(component, {
localVue,
Expand Down

0 comments on commit aa73570

Please sign in to comment.