@@ -5,7 +5,7 @@ import type { AdapterTestNameMethods } from './methods.js'
55import methodTests from './methods.js'
66import type { AdapterTestNameSyntax } from './syntax.js'
77import syntaxTests from './syntax.js'
8- import { describe , it , afterAll } from 'vitest'
8+ import { describe , it } from 'vitest'
99
1010export type TestSuiteOptions = {
1111 app : Application
@@ -32,9 +32,6 @@ export const defineTestSuite = (defineOptions?: DefineTestSuiteOptions) => {
3232 return ( options : TestSuiteOptions ) => {
3333 const { app, serviceName, idProp = 'id' } = options
3434
35- const skippedTests : AdapterTestName [ ] = [ ]
36- const allTests : AdapterTestName [ ] = [ ]
37-
3835 const test = ( name : string , runner : any ) => {
3936 let skip = false
4037 if ( defineOptions ?. blacklist ?. includes ( name as AdapterTestName ) ) {
@@ -46,25 +43,60 @@ export const defineTestSuite = (defineOptions?: DefineTestSuiteOptions) => {
4643 ) {
4744 skip = true
4845 }
49- const its = skip ? it . skip : it
46+ const maybeSkip = skip ? it . skip : it
5047
51- if ( skip ) {
52- skippedTests . push ( name as AdapterTestName )
53- }
48+ maybeSkip ( name , runner )
49+ }
5450
55- allTests . push ( name as AdapterTestName )
51+ describe ( `app.service('${ serviceName } ') with options.id: '${ idProp } '` , ( ) => {
52+ beforeAll ( async ( ) => {
53+ const service = app . service ( serviceName )
5654
57- its ( name , runner )
58- }
55+ // test create
56+ const doug = await service . create ( {
57+ name : 'Doug' ,
58+ age : 32 ,
59+ } )
60+
61+ assert . ok (
62+ doug [ idProp ] !== null ,
63+ `simple 'create' failed (no ${ idProp } ). Before you start to test the adapter make sure simple create works.` ,
64+ )
65+ assert . strictEqual (
66+ doug . name ,
67+ 'Doug' ,
68+ "simple 'create' failed (no name). Before you start to test the adapter make sure simple create works." ,
69+ )
70+ assert . strictEqual (
71+ doug . age ,
72+ 32 ,
73+ "simple 'create' failed (no age). Before you start to test the adapter make sure simple create works." ,
74+ )
75+
76+ // test delete
5977
60- describe ( `Adapter tests for '${ serviceName } ' service with '${ idProp } ' id property` , ( ) => {
61- afterAll ( ( ) => {
62- if ( skippedTests . length ) {
63- console . log (
64- `\nSkipped the following ${ skippedTests . length } Feathers adapter test(s) out of ${ allTests . length } total:` ,
65- )
66- console . log ( JSON . stringify ( skippedTests , null , ' ' ) )
67- }
78+ const items = await service . find ( { paginate : false } )
79+ assert . ok (
80+ Array . isArray ( items ) ,
81+ 'find with paginate:false did not return an array. Before you start to test the adapter make sure simple find works.' ,
82+ )
83+ assert . strictEqual (
84+ items . length ,
85+ 1 ,
86+ 'find should return an item. Before you start to test the adapter make sure simple find works.' ,
87+ )
88+ assert . ok (
89+ idProp in items [ 0 ] ,
90+ `'find' should return an item with ${ idProp } . Before you start to test the adapter make sure simple find works.` ,
91+ )
92+ await Promise . all (
93+ items . map ( ( item : any ) => service . remove ( item [ idProp ] ) ) ,
94+ )
95+ const itemsAfterRemove = await service . find ( { paginate : false } )
96+ assert . ok (
97+ itemsAfterRemove . length === 0 ,
98+ "'remove' does not work. Before you start to test the adapter make sure simple remove works." ,
99+ )
68100 } )
69101
70102 basicTests ( { test, app, serviceName, idProp } )
0 commit comments