Skip to content

Commit

Permalink
chore: drop eslint (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm authored Aug 10, 2024
1 parent 197b845 commit cf05134
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 82 deletions.
16 changes: 8 additions & 8 deletions lib/fastifyAwilixPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const { AwilixManager } = require('awilix-manager')
const fp = require('fastify-plugin')

const diContainerProxy = awilix.createContainer({
injectionMode: 'PROXY',
injectionMode: 'PROXY'
})

const diContainerClassic = awilix.createContainer({
injectionMode: 'CLASSIC',
injectionMode: 'CLASSIC'
})

function plugin(fastify, opts, next) {
function plugin (fastify, opts, next) {
if (opts.container && opts.injectionMode) {
return next(
new Error(
'If you are passing pre-created container explicitly, you cannot specify injection mode',
),
'If you are passing pre-created container explicitly, you cannot specify injection mode'
)
)
}

Expand All @@ -32,7 +32,7 @@ function plugin(fastify, opts, next) {
asyncDispose: opts.asyncDispose,
asyncInit: opts.asyncInit,
eagerInject: opts.eagerInject,
strictBooleanEnforced: opts.strictBooleanEnforced,
strictBooleanEnforced: opts.strictBooleanEnforced
})
const disposeOnResponse = opts.disposeOnResponse === true || opts.disposeOnResponse === undefined
const disposeOnClose = opts.disposeOnClose === true || opts.disposeOnClose === undefined
Expand Down Expand Up @@ -80,12 +80,12 @@ function plugin(fastify, opts, next) {

const fastifyAwilixPlugin = fp(plugin, {
fastify: '4.x',
name: '@fastify/awilix',
name: '@fastify/awilix'
})

module.exports = {
diContainer: diContainerProxy,
diContainerProxy,
diContainerClassic,
fastifyAwilixPlugin,
fastifyAwilixPlugin
}
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const {
diContainer,
fastifyAwilixPlugin,
diContainerProxy,
diContainerClassic,
diContainerClassic
} = require('./fastifyAwilixPlugin')

module.exports = {
diContainer,
diContainerClassic,
diContainerProxy,
fastifyAwilixPlugin,
fastifyAwilixPlugin
}
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"test": "c8 --100 node --test",
"test:ci": "npm run lint && npm run test:typescript && npm run test",
"test:typescript": "tsd",
"lint": "eslint \"lib/**/*.js\" lib/index.js",
"lint:fix": "eslint --fix \"lib/**/*.js\" lib/index.js",
"prettier": "prettier --write \"{lib,test}/**/*.js\" lib/index.js lib/index.d.ts"
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy"
},
"dependencies": {
"awilix-manager": "^5.1.0",
Expand All @@ -33,11 +32,9 @@
"@types/node": "^22.0.0",
"awilix": "^10.0.2",
"c8": "^10.1.2",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"fastify": "^4.26.2",
"prettier": "^3.2.5",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tsd": "^0.31.0"
},
"homepage": "http://github.com/fastify/fastify-awilix",
Expand Down
32 changes: 15 additions & 17 deletions test/awilixManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@ let isInittedGlobal = false
let isDisposedGlobal = false

class InitSetClass {
constructor() {
constructor () {
isInittedGlobal = true
}
}

class AsyncInitSetClass {
constructor() {}

async init() {
async init () {
isInittedGlobal = true
}

async dispose() {
async dispose () {
isDisposedGlobal = true
}
}

const variations = [
{
injectionMode: 'PROXY',
container: diContainer,
container: diContainer
},
{
injectionMode: 'CLASSIC',
container: diContainerClassic,
},
container: diContainerClassic
}
]

describe('awilixManager', () => {
Expand All @@ -63,13 +61,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(InitSetClass, {
lifetime: 'SINGLETON',
eagerInject: true,
}),
eagerInject: true
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
eagerInject: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()

Expand All @@ -81,13 +79,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(AsyncInitSetClass, {
lifetime: 'SINGLETON',
asyncInit: 'init',
}),
asyncInit: 'init'
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
asyncInit: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()

Expand All @@ -99,13 +97,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(AsyncInitSetClass, {
lifetime: 'SINGLETON',
asyncDispose: 'dispose',
}),
asyncDispose: 'dispose'
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
asyncDispose: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()
await app.close()
Expand Down
68 changes: 34 additions & 34 deletions test/fastifyAwilixPlugin.dispose.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const assert = require('node:assert')
const { fastifyAwilixPlugin, diContainer, diContainerClassic } = require('../lib')

class UserRepository {
constructor() {
constructor () {
this.disposeCounter = 0
}

dispose() {
dispose () {
this.disposeCounter++
}
}
Expand All @@ -23,15 +23,15 @@ let storedUserRepositoryScoped
const variations = [
{
injectionMode: 'PROXY',
container: diContainer,
container: diContainer
},
{
injectionMode: 'CLASSIC',
container: diContainerClassic,
},
container: diContainerClassic
}
]

function getCompletedRequests(output) {
function getCompletedRequests (output) {
return output.filter((line) => {
try {
return JSON.parse(line).msg === 'request completed'
Expand All @@ -43,7 +43,7 @@ function getCompletedRequests(output) {

describe('fastifyAwilixPlugin', () => {
let app, output
let write = process.stdout.write
const write = process.stdout.write

beforeEach(() => {
storedUserRepository = undefined
Expand All @@ -65,7 +65,7 @@ describe('fastifyAwilixPlugin', () => {
assert.equal(userRepository.disposeCounter, 0)

res.send({
status: 'OK',
status: 'OK'
})
}

Expand All @@ -80,7 +80,7 @@ describe('fastifyAwilixPlugin', () => {
assert.equal(userRepositoryScoped.disposeCounter, 0)

res.send({
status: 'OK',
status: 'OK'
})
}

Expand All @@ -89,13 +89,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: false,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -116,13 +116,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -147,13 +147,13 @@ describe('fastifyAwilixPlugin', () => {
await app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

let storedError = null
Expand Down Expand Up @@ -181,21 +181,21 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})

variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
app.addHook('onRequest', (request, reply, done) => {
request.diScope.register({
userRepositoryScoped: asClass(UserRepository, {
lifetime: Lifetime.SCOPED,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
done()
})
Expand All @@ -220,21 +220,21 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})

variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
app.addHook('onRequest', (request, reply, done) => {
request.diScope.register({
userRepositoryScoped: asClass(UserRepository, {
lifetime: Lifetime.SCOPED,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
done()
})
Expand All @@ -261,13 +261,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -287,13 +287,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: false,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand Down
Loading

0 comments on commit cf05134

Please sign in to comment.